ASoC: dapm: Use DAPM mutex for DAPM ops instead of codec mutex
[linux-2.6.git] / sound / soc / pxa / corgi.c
index fa69faa..28757fb 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright 2005 Wolfson Microelectronics PLC.
  * Copyright 2005 Openedhand Ltd.
  *
- * Authors: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
+ * Authors: Liam Girdwood <lrg@slimlogic.co.uk>
  *          Richard Purdie <richard@openedhand.com>
  *
  *  This program is free software; you can redistribute  it and/or modify it
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/timer.h>
+#include <linux/i2c.h>
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/soc.h>
-#include <sound/soc-dapm.h>
 
 #include <asm/mach-types.h>
-#include <mach/pxa-regs.h>
-#include <mach/hardware.h>
 #include <mach/corgi.h>
 #include <mach/audio.h>
 
 #include "../codecs/wm8731.h"
-#include "pxa2xx-pcm.h"
 #include "pxa2xx-i2s.h"
 
 #define CORGI_HP        0
@@ -50,81 +47,84 @@ static int corgi_spk_func;
 
 static void corgi_ext_control(struct snd_soc_codec *codec)
 {
+       struct snd_soc_dapm_context *dapm = &codec->dapm;
+
        /* set up jack connection */
        switch (corgi_jack_func) {
        case CORGI_HP:
                /* set = unmute headphone */
                gpio_set_value(CORGI_GPIO_MUTE_L, 1);
                gpio_set_value(CORGI_GPIO_MUTE_R, 1);
-               snd_soc_dapm_disable_pin(codec, "Mic Jack");
-               snd_soc_dapm_disable_pin(codec, "Line Jack");
-               snd_soc_dapm_enable_pin(codec, "Headphone Jack");
-               snd_soc_dapm_disable_pin(codec, "Headset Jack");
+               snd_soc_dapm_disable_pin(dapm, "Mic Jack");
+               snd_soc_dapm_disable_pin(dapm, "Line Jack");
+               snd_soc_dapm_enable_pin(dapm, "Headphone Jack");
+               snd_soc_dapm_disable_pin(dapm, "Headset Jack");
                break;
        case CORGI_MIC:
                /* reset = mute headphone */
                gpio_set_value(CORGI_GPIO_MUTE_L, 0);
                gpio_set_value(CORGI_GPIO_MUTE_R, 0);
-               snd_soc_dapm_enable_pin(codec, "Mic Jack");
-               snd_soc_dapm_disable_pin(codec, "Line Jack");
-               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
-               snd_soc_dapm_disable_pin(codec, "Headset Jack");
+               snd_soc_dapm_enable_pin(dapm, "Mic Jack");
+               snd_soc_dapm_disable_pin(dapm, "Line Jack");
+               snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
+               snd_soc_dapm_disable_pin(dapm, "Headset Jack");
                break;
        case CORGI_LINE:
                gpio_set_value(CORGI_GPIO_MUTE_L, 0);
                gpio_set_value(CORGI_GPIO_MUTE_R, 0);
-               snd_soc_dapm_disable_pin(codec, "Mic Jack");
-               snd_soc_dapm_enable_pin(codec, "Line Jack");
-               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
-               snd_soc_dapm_disable_pin(codec, "Headset Jack");
+               snd_soc_dapm_disable_pin(dapm, "Mic Jack");
+               snd_soc_dapm_enable_pin(dapm, "Line Jack");
+               snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
+               snd_soc_dapm_disable_pin(dapm, "Headset Jack");
                break;
        case CORGI_HEADSET:
                gpio_set_value(CORGI_GPIO_MUTE_L, 0);
                gpio_set_value(CORGI_GPIO_MUTE_R, 1);
-               snd_soc_dapm_enable_pin(codec, "Mic Jack");
-               snd_soc_dapm_disable_pin(codec, "Line Jack");
-               snd_soc_dapm_disable_pin(codec, "Headphone Jack");
-               snd_soc_dapm_enable_pin(codec, "Headset Jack");
+               snd_soc_dapm_enable_pin(dapm, "Mic Jack");
+               snd_soc_dapm_disable_pin(dapm, "Line Jack");
+               snd_soc_dapm_disable_pin(dapm, "Headphone Jack");
+               snd_soc_dapm_enable_pin(dapm, "Headset Jack");
                break;
        }
 
        if (corgi_spk_func == CORGI_SPK_ON)
-               snd_soc_dapm_enable_pin(codec, "Ext Spk");
+               snd_soc_dapm_enable_pin(dapm, "Ext Spk");
        else
-               snd_soc_dapm_disable_pin(codec, "Ext Spk");
+               snd_soc_dapm_disable_pin(dapm, "Ext Spk");
 
        /* signal a DAPM event */
-       snd_soc_dapm_sync(codec);
+       snd_soc_dapm_sync(dapm);
 }
 
 static int corgi_startup(struct snd_pcm_substream *substream)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec *codec = rtd->socdev->codec;
+       struct snd_soc_codec *codec = rtd->codec;
+
+       mutex_lock(&codec->mutex);
 
        /* check the jack status at stream startup */
        corgi_ext_control(codec);
+
+       mutex_unlock(&codec->mutex);
+
        return 0;
 }
 
 /* we need to unmute the HP at shutdown as the mute burns power on corgi */
-static int corgi_shutdown(struct snd_pcm_substream *substream)
+static void corgi_shutdown(struct snd_pcm_substream *substream)
 {
-       struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_codec *codec = rtd->socdev->codec;
-
        /* set = unmute headphone */
        gpio_set_value(CORGI_GPIO_MUTE_L, 1);
        gpio_set_value(CORGI_GPIO_MUTE_R, 1);
-       return 0;
 }
 
 static int corgi_hw_params(struct snd_pcm_substream *substream,
        struct snd_pcm_hw_params *params)
 {
        struct snd_soc_pcm_runtime *rtd = substream->private_data;
-       struct snd_soc_dai *codec_dai = rtd->dai->codec_dai;
-       struct snd_soc_dai *cpu_dai = rtd->dai->cpu_dai;
+       struct snd_soc_dai *codec_dai = rtd->codec_dai;
+       struct snd_soc_dai *cpu_dai = rtd->cpu_dai;
        unsigned int clk = 0;
        int ret = 0;
 
@@ -155,7 +155,7 @@ static int corgi_hw_params(struct snd_pcm_substream *substream,
                return ret;
 
        /* set the codec system clock for DAC and ADC */
-       ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK, clk,
+       ret = snd_soc_dai_set_sysclk(codec_dai, WM8731_SYSCLK_XTAL, clk,
                SND_SOC_CLOCK_IN);
        if (ret < 0)
                return ret;
@@ -277,29 +277,29 @@ static const struct snd_kcontrol_new wm8731_corgi_controls[] = {
 /*
  * Logic for a wm8731 as connected on a Sharp SL-C7x0 Device
  */
-static int corgi_wm8731_init(struct snd_soc_codec *codec)
+static int corgi_wm8731_init(struct snd_soc_pcm_runtime *rtd)
 {
-       int i, err;
+       struct snd_soc_codec *codec = rtd->codec;
+       struct snd_soc_dapm_context *dapm = &codec->dapm;
+       int err;
 
-       snd_soc_dapm_disable_pin(codec, "LLINEIN");
-       snd_soc_dapm_disable_pin(codec, "RLINEIN");
+       snd_soc_dapm_nc_pin(dapm, "LLINEIN");
+       snd_soc_dapm_nc_pin(dapm, "RLINEIN");
 
        /* Add corgi specific controls */
-       for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) {
-               err = snd_ctl_add(codec->card,
-                       snd_soc_cnew(&wm8731_corgi_controls[i], codec, NULL));
-               if (err < 0)
-                       return err;
-       }
+       err = snd_soc_add_controls(codec, wm8731_corgi_controls,
+                               ARRAY_SIZE(wm8731_corgi_controls));
+       if (err < 0)
+               return err;
 
        /* Add corgi specific widgets */
-       snd_soc_dapm_new_controls(codec, wm8731_dapm_widgets,
+       snd_soc_dapm_new_controls(dapm, wm8731_dapm_widgets,
                                  ARRAY_SIZE(wm8731_dapm_widgets));
 
        /* Set up corgi specific audio path audio_map */
-       snd_soc_dapm_add_routes(codec, audio_map, ARRAY_SIZE(audio_map));
+       snd_soc_dapm_add_routes(dapm, audio_map, ARRAY_SIZE(audio_map));
 
-       snd_soc_dapm_sync(codec);
+       snd_soc_dapm_sync(dapm);
        return 0;
 }
 
@@ -307,32 +307,21 @@ static int corgi_wm8731_init(struct snd_soc_codec *codec)
 static struct snd_soc_dai_link corgi_dai = {
        .name = "WM8731",
        .stream_name = "WM8731",
-       .cpu_dai = &pxa_i2s_dai,
-       .codec_dai = &wm8731_dai,
+       .cpu_dai_name = "pxa2xx-i2s",
+       .codec_dai_name = "wm8731-hifi",
+       .platform_name = "pxa-pcm-audio",
+       .codec_name = "wm8731.0-001b",
        .init = corgi_wm8731_init,
        .ops = &corgi_ops,
 };
 
 /* corgi audio machine driver */
-static struct snd_soc_machine snd_soc_machine_corgi = {
+static struct snd_soc_card snd_soc_corgi = {
        .name = "Corgi",
        .dai_link = &corgi_dai,
        .num_links = 1,
 };
 
-/* corgi audio private data */
-static struct wm8731_setup_data corgi_wm8731_setup = {
-       .i2c_address = 0x1b,
-};
-
-/* corgi audio subsystem */
-static struct snd_soc_device corgi_snd_devdata = {
-       .machine = &snd_soc_machine_corgi,
-       .platform = &pxa2xx_soc_platform,
-       .codec_dev = &soc_codec_dev_wm8731,
-       .codec_data = &corgi_wm8731_setup,
-};
-
 static struct platform_device *corgi_snd_device;
 
 static int __init corgi_init(void)
@@ -347,8 +336,7 @@ static int __init corgi_init(void)
        if (!corgi_snd_device)
                return -ENOMEM;
 
-       platform_set_drvdata(corgi_snd_device, &corgi_snd_devdata);
-       corgi_snd_devdata.dev = &corgi_snd_device->dev;
+       platform_set_drvdata(corgi_snd_device, &snd_soc_corgi);
        ret = platform_device_add(corgi_snd_device);
 
        if (ret)