]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/soc/soc-core.c
ALSA: ASoC: Pass the DAI being configured into CPU DAI probe and remove
[linux-2.6-omap-h63xx.git] / sound / soc / soc-core.c
index 9eb5479787c1d32203b17c1a037750a961c11f17..c96a6184d66eccfcf1bc31bd650c92db8bee2b7b 100644 (file)
  *  Free Software Foundation;  either version 2 of the  License, or (at your
  *  option) any later version.
  *
- *  Revision history
- *    12th Aug 2005   Initial version.
- *    25th Oct 2005   Working Codec, Interface and Platform registration.
- *
  *  TODO:
  *   o Add hw rules to enforce rates, etc.
  *   o More testing with other codecs/machines.
@@ -112,9 +108,9 @@ static int soc_ac97_dev_register(struct snd_soc_codec *codec)
 }
 #endif
 
-static inline const charget_dai_name(int type)
+static inline const char *get_dai_name(int type)
 {
-       switch(type) {
+       switch (type) {
        case SND_SOC_DAI_AC97_BUS:
        case SND_SOC_DAI_AC97:
                return "AC97";
@@ -182,9 +178,11 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
        /* Check that the codec and cpu DAI's are compatible */
        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
                runtime->hw.rate_min =
-                       max(codec_dai->playback.rate_min, cpu_dai->playback.rate_min);
+                       max(codec_dai->playback.rate_min,
+                           cpu_dai->playback.rate_min);
                runtime->hw.rate_max =
-                       min(codec_dai->playback.rate_max, cpu_dai->playback.rate_max);
+                       min(codec_dai->playback.rate_max,
+                           cpu_dai->playback.rate_max);
                runtime->hw.channels_min =
                        max(codec_dai->playback.channels_min,
                                cpu_dai->playback.channels_min);
@@ -197,9 +195,11 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
                        codec_dai->playback.rates & cpu_dai->playback.rates;
        } else {
                runtime->hw.rate_min =
-                       max(codec_dai->capture.rate_min, cpu_dai->capture.rate_min);
+                       max(codec_dai->capture.rate_min,
+                           cpu_dai->capture.rate_min);
                runtime->hw.rate_max =
-                       min(codec_dai->capture.rate_max, cpu_dai->capture.rate_max);
+                       min(codec_dai->capture.rate_max,
+                           cpu_dai->capture.rate_max);
                runtime->hw.channels_min =
                        max(codec_dai->capture.channels_min,
                                cpu_dai->capture.channels_min);
@@ -229,7 +229,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
                goto machine_err;
        }
 
-       dbg("asoc: %s <-> %s info:\n",codec_dai->name, cpu_dai->name);
+       dbg("asoc: %s <-> %s info:\n", codec_dai->name, cpu_dai->name);
        dbg("asoc: rate mask 0x%x\n", runtime->hw.rates);
        dbg("asoc: min ch %d max ch %d\n", runtime->hw.channels_min,
                runtime->hw.channels_max);
@@ -276,7 +276,7 @@ static void close_delayed_work(struct work_struct *work)
        int i;
 
        mutex_lock(&pcm_mutex);
-       for(i = 0; i < codec->num_dai; i++) {
+       for (i = 0; i < codec->num_dai; i++) {
                codec_dai = &codec->dai[i];
 
                dbg("pop wq checking: %s status: %s waiting: %s\n",
@@ -287,12 +287,12 @@ static void close_delayed_work(struct work_struct *work)
                /* are we waiting on this codec DAI stream */
                if (codec_dai->pop_wait == 1) {
 
-                       /* power down the codec to D1 if no longer active */
+                       /* Reduce power if no longer active */
                        if (codec->active == 0) {
                                dbg("pop wq D1 %s %s\n", codec->name,
                                        codec_dai->playback.stream_name);
-                               snd_soc_dapm_device_event(socdev,
-                                       SNDRV_CTL_POWER_D1);
+                               snd_soc_dapm_set_bias_level(socdev,
+                                       SND_SOC_BIAS_PREPARE);
                        }
 
                        codec_dai->pop_wait = 0;
@@ -300,12 +300,12 @@ static void close_delayed_work(struct work_struct *work)
                                codec_dai->playback.stream_name,
                                SND_SOC_DAPM_STREAM_STOP);
 
-                       /* power down the codec power domain if no longer active */
+                       /* Fall into standby if no longer active */
                        if (codec->active == 0) {
                                dbg("pop wq D3 %s %s\n", codec->name,
                                        codec_dai->playback.stream_name);
-                               snd_soc_dapm_device_event(socdev,
-                                       SNDRV_CTL_POWER_D3hot);
+                               snd_soc_dapm_set_bias_level(socdev,
+                                       SND_SOC_BIAS_STANDBY);
                        }
                }
        }
@@ -365,8 +365,8 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
                        SND_SOC_DAPM_STREAM_STOP);
 
                if (codec->active == 0 && codec_dai->pop_wait == 0)
-                       snd_soc_dapm_device_event(socdev,
-                                               SNDRV_CTL_POWER_D3hot);
+                       snd_soc_dapm_set_bias_level(socdev,
+                                               SND_SOC_BIAS_STANDBY);
        }
 
        mutex_unlock(&pcm_mutex);
@@ -439,9 +439,10 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
                }
        } else {
                /* no delayed work - do we need to power up codec */
-               if (codec->dapm_state != SNDRV_CTL_POWER_D0) {
+               if (codec->bias_level != SND_SOC_BIAS_ON) {
 
-                       snd_soc_dapm_device_event(socdev,  SNDRV_CTL_POWER_D1);
+                       snd_soc_dapm_set_bias_level(socdev,
+                                                   SND_SOC_BIAS_PREPARE);
 
                        if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
                                snd_soc_dapm_stream_event(codec,
@@ -452,7 +453,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
                                        codec_dai->capture.stream_name,
                                        SND_SOC_DAPM_STREAM_START);
 
-                       snd_soc_dapm_device_event(socdev, SNDRV_CTL_POWER_D0);
+                       snd_soc_dapm_set_bias_level(socdev, SND_SOC_BIAS_ON);
                        if (codec_dai->dai_ops.digital_mute)
                                codec_dai->dai_ops.digital_mute(codec_dai, 0);
 
@@ -514,7 +515,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
        if (cpu_dai->ops.hw_params) {
                ret = cpu_dai->ops.hw_params(substream, params);
                if (ret < 0) {
-                       printk(KERN_ERR "asoc: can't set interface %s hw params\n",
+                       printk(KERN_ERR "asoc: interface %s hw params failed\n",
                                cpu_dai->name);
                        goto interface_err;
                }
@@ -523,7 +524,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
        if (platform->pcm_ops->hw_params) {
                ret = platform->pcm_ops->hw_params(substream, params);
                if (ret < 0) {
-                       printk(KERN_ERR "asoc: can't set platform %s hw params\n",
+                       printk(KERN_ERR "asoc: platform %s hw params failed\n",
                                platform->name);
                        goto platform_err;
                }
@@ -542,7 +543,7 @@ interface_err:
                codec_dai->ops.hw_free(substream);
 
 codec_err:
-       if(machine->ops && machine->ops->hw_free)
+       if (machine->ops && machine->ops->hw_free)
                machine->ops->hw_free(substream);
 
        mutex_unlock(&pcm_mutex);
@@ -631,15 +632,15 @@ static struct snd_pcm_ops soc_pcm_ops = {
 /* powers down audio subsystem for suspend */
 static int soc_suspend(struct platform_device *pdev, pm_message_t state)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_machine *machine = socdev->machine;
-       struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_machine *machine = socdev->machine;
+       struct snd_soc_platform *platform = socdev->platform;
+       struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
        struct snd_soc_codec *codec = socdev->codec;
        int i;
 
        /* mute any active DAC's */
-       for(i = 0; i < machine->num_links; i++) {
+       for (i = 0; i < machine->num_links; i++) {
                struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
                if (dai->dai_ops.digital_mute && dai->playback.active)
                        dai->dai_ops.digital_mute(dai, 1);
@@ -652,7 +653,7 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
        if (machine->suspend_pre)
                machine->suspend_pre(pdev, state);
 
-       for(i = 0; i < machine->num_links; i++) {
+       for (i = 0; i < machine->num_links; i++) {
                struct snd_soc_cpu_dai  *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->suspend && cpu_dai->type != SND_SOC_DAI_AC97)
                        cpu_dai->suspend(pdev, cpu_dai);
@@ -662,9 +663,9 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
 
        /* close any waiting streams and save state */
        run_delayed_work(&socdev->delayed_work);
-       codec->suspend_dapm_state = codec->dapm_state;
+       codec->suspend_bias_level = codec->bias_level;
 
-       for(i = 0; i < codec->num_dai; i++) {
+       for (i = 0; i < codec->num_dai; i++) {
                char *stream = codec->dai[i].playback.stream_name;
                if (stream != NULL)
                        snd_soc_dapm_stream_event(codec, stream,
@@ -678,7 +679,7 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
        if (codec_dev->suspend)
                codec_dev->suspend(pdev, state);
 
-       for(i = 0; i < machine->num_links; i++) {
+       for (i = 0; i < machine->num_links; i++) {
                struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->suspend && cpu_dai->type == SND_SOC_DAI_AC97)
                        cpu_dai->suspend(pdev, cpu_dai);
@@ -693,17 +694,17 @@ static int soc_suspend(struct platform_device *pdev, pm_message_t state)
 /* powers up audio subsystem after a suspend */
 static int soc_resume(struct platform_device *pdev)
 {
-       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
-       struct snd_soc_machine *machine = socdev->machine;
-       struct snd_soc_platform *platform = socdev->platform;
-       struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
+       struct snd_soc_device *socdev = platform_get_drvdata(pdev);
+       struct snd_soc_machine *machine = socdev->machine;
+       struct snd_soc_platform *platform = socdev->platform;
+       struct snd_soc_codec_device *codec_dev = socdev->codec_dev;
        struct snd_soc_codec *codec = socdev->codec;
        int i;
 
        if (machine->resume_pre)
                machine->resume_pre(pdev);
 
-       for(i = 0; i < machine->num_links; i++) {
+       for (i = 0; i < machine->num_links; i++) {
                struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->resume && cpu_dai->type == SND_SOC_DAI_AC97)
                        cpu_dai->resume(pdev, cpu_dai);
@@ -712,8 +713,8 @@ static int soc_resume(struct platform_device *pdev)
        if (codec_dev->resume)
                codec_dev->resume(pdev);
 
-       for(i = 0; i < codec->num_dai; i++) {
-               charstream = codec->dai[i].playback.stream_name;
+       for (i = 0; i < codec->num_dai; i++) {
+               char *stream = codec->dai[i].playback.stream_name;
                if (stream != NULL)
                        snd_soc_dapm_stream_event(codec, stream,
                                SND_SOC_DAPM_STREAM_RESUME);
@@ -723,14 +724,14 @@ static int soc_resume(struct platform_device *pdev)
                                SND_SOC_DAPM_STREAM_RESUME);
        }
 
-       /* unmute any active DAC's */
-       for(i = 0; i < machine->num_links; i++) {
+       /* unmute any active DACs */
+       for (i = 0; i < machine->num_links; i++) {
                struct snd_soc_codec_dai *dai = machine->dai_link[i].codec_dai;
                if (dai->dai_ops.digital_mute && dai->playback.active)
                        dai->dai_ops.digital_mute(dai, 0);
        }
 
-       for(i = 0; i < machine->num_links; i++) {
+       for (i = 0; i < machine->num_links; i++) {
                struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->resume && cpu_dai->type != SND_SOC_DAI_AC97)
                        cpu_dai->resume(pdev, cpu_dai);
@@ -760,28 +761,28 @@ static int soc_probe(struct platform_device *pdev)
 
        if (machine->probe) {
                ret = machine->probe(pdev);
-               if(ret < 0)
+               if (ret < 0)
                        return ret;
        }
 
        for (i = 0; i < machine->num_links; i++) {
                struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->probe) {
-                       ret = cpu_dai->probe(pdev);
-                       if(ret < 0)
+                       ret = cpu_dai->probe(pdev, cpu_dai);
+                       if (ret < 0)
                                goto cpu_dai_err;
                }
        }
 
        if (codec_dev->probe) {
                ret = codec_dev->probe(pdev);
-               if(ret < 0)
+               if (ret < 0)
                        goto cpu_dai_err;
        }
 
        if (platform->probe) {
                ret = platform->probe(pdev);
-               if(ret < 0)
+               if (ret < 0)
                        goto platform_err;
        }
 
@@ -797,7 +798,7 @@ cpu_dai_err:
        for (i--; i >= 0; i--) {
                struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->remove)
-                       cpu_dai->remove(pdev);
+                       cpu_dai->remove(pdev, cpu_dai);
        }
 
        if (machine->remove)
@@ -826,7 +827,7 @@ static int soc_remove(struct platform_device *pdev)
        for (i = 0; i < machine->num_links; i++) {
                struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[i].cpu_dai;
                if (cpu_dai->remove)
-                       cpu_dai->remove(pdev);
+                       cpu_dai->remove(pdev, cpu_dai);
        }
 
        if (machine->remove)
@@ -839,6 +840,7 @@ static int soc_remove(struct platform_device *pdev)
 static struct platform_driver soc_driver = {
        .driver         = {
                .name           = "soc-audio",
+               .owner          = THIS_MODULE,
        },
        .probe          = soc_probe,
        .remove         = soc_remove,
@@ -867,7 +869,7 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
        codec_dai->codec = socdev->codec;
 
        /* check client and interface hw capabilities */
-       sprintf(new_name, "%s %s-%s-%d",dai_link->stream_name, codec_dai->name,
+       sprintf(new_name, "%s %s-%s-%d", dai_link->stream_name, codec_dai->name,
                get_dai_name(cpu_dai->type), num);
 
        if (codec_dai->playback.channels_min)
@@ -878,7 +880,8 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
        ret = snd_pcm_new(codec->card, new_name, codec->pcm_devs++, playback,
                capture, &pcm);
        if (ret < 0) {
-               printk(KERN_ERR "asoc: can't create pcm for codec %s\n", codec->name);
+               printk(KERN_ERR "asoc: can't create pcm for codec %s\n",
+                       codec->name);
                kfree(rtd);
                return ret;
        }
@@ -927,8 +930,9 @@ static ssize_t codec_reg_show(struct device *dev,
                step = codec->reg_cache_step;
 
        count += sprintf(buf, "%s registers\n", codec->name);
-       for(i = 0; i < codec->reg_cache_size; i += step)
-               count += sprintf(buf + count, "%2x: %4x\n", i, codec->read(codec, i));
+       for (i = 0; i < codec->reg_cache_size; i += step)
+               count += sprintf(buf + count, "%2x: %4x\n", i,
+                       codec->read(codec, i));
 
        return count;
 }
@@ -1071,7 +1075,7 @@ int snd_soc_new_pcms(struct snd_soc_device *socdev, int idx, const char *xid)
        strncpy(codec->card->driver, codec->name, sizeof(codec->card->driver));
 
        /* create the pcms */
-       for(i = 0; i < machine->num_links; i++) {
+       for (i = 0; i < machine->num_links; i++) {
                ret = soc_new_pcm(socdev, &machine->dai_link[i], i);
                if (ret < 0) {
                        printk(KERN_ERR "asoc: can't create pcm %s\n",
@@ -1101,7 +1105,7 @@ int snd_soc_register_card(struct snd_soc_device *socdev)
        struct snd_soc_machine *machine = socdev->machine;
        int ret = 0, i, ac97 = 0, err = 0;
 
-       for(i = 0; i < machine->num_links; i++) {
+       for (i = 0; i < machine->num_links; i++) {
                if (socdev->machine->dai_link[i].init) {
                        err = socdev->machine->dai_link[i].init(codec);
                        if (err < 0) {
@@ -1110,7 +1114,7 @@ int snd_soc_register_card(struct snd_soc_device *socdev)
                                continue;
                        }
                }
-               if (socdev->machine->dai_link[i].codec_dai->type == 
+               if (socdev->machine->dai_link[i].codec_dai->type ==
                        SND_SOC_DAI_AC97_BUS)
                        ac97 = 1;
        }
@@ -1121,7 +1125,7 @@ int snd_soc_register_card(struct snd_soc_device *socdev)
 
        ret = snd_card_register(codec->card);
        if (ret < 0) {
-               printk(KERN_ERR "asoc: failed to register soundcard for codec %s\n",
+               printk(KERN_ERR "asoc: failed to register soundcard for %s\n",
                                codec->name);
                goto out;
        }
@@ -1145,7 +1149,7 @@ int snd_soc_register_card(struct snd_soc_device *socdev)
 
        err = device_create_file(socdev->dev, &dev_attr_codec_reg);
        if (err < 0)
-               printk(KERN_WARNING "asoc: failed to add codec sysfs entries\n");
+               printk(KERN_WARNING "asoc: failed to add codec sysfs files\n");
 
        mutex_unlock(&codec->mutex);
 
@@ -1171,7 +1175,7 @@ void snd_soc_free_pcms(struct snd_soc_device *socdev)
 
        mutex_lock(&codec->mutex);
 #ifdef CONFIG_SND_SOC_AC97_BUS
-       for(i = 0; i < codec->num_dai; i++) {
+       for (i = 0; i < codec->num_dai; i++) {
                codec_dai = &codec->dai[i];
                if (codec_dai->type == SND_SOC_DAI_AC97_BUS && codec->ac97) {
                        soc_ac97_dev_unregister(codec);
@@ -1281,7 +1285,8 @@ int snd_soc_get_enum_double(struct snd_kcontrol *kcontrol,
        for (bitmask = 1; bitmask < e->mask; bitmask <<= 1)
                ;
        val = snd_soc_read(codec, e->reg);
-       ucontrol->value.enumerated.item[0] = (val >> e->shift_l) & (bitmask - 1);
+       ucontrol->value.enumerated.item[0]
+               = (val >> e->shift_l) & (bitmask - 1);
        if (e->shift_l != e->shift_r)
                ucontrol->value.enumerated.item[1] =
                        (val >> e->shift_r) & (bitmask - 1);
@@ -1575,7 +1580,8 @@ int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
        val = val << shift;
        val2 = val2 << shift;
 
-       if ((err = snd_soc_update_bits(codec, reg, val_mask, val)) < 0)
+       err = snd_soc_update_bits(codec, reg, val_mask, val);
+       if (err < 0)
                return err;
 
        err = snd_soc_update_bits(codec, reg2, val_mask, val2);
@@ -1583,6 +1589,78 @@ int snd_soc_put_volsw_2r(struct snd_kcontrol *kcontrol,
 }
 EXPORT_SYMBOL_GPL(snd_soc_put_volsw_2r);
 
+/**
+ * snd_soc_info_volsw_s8 - signed mixer info callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to provide information about a signed mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_info_volsw_s8(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_info *uinfo)
+{
+       int max = (signed char)((kcontrol->private_value >> 16) & 0xff);
+       int min = (signed char)((kcontrol->private_value >> 24) & 0xff);
+
+       uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+       uinfo->count = 2;
+       uinfo->value.integer.min = 0;
+       uinfo->value.integer.max = max-min;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_info_volsw_s8);
+
+/**
+ * snd_soc_get_volsw_s8 - signed mixer get callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to get the value of a signed mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_get_volsw_s8(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       int reg = kcontrol->private_value & 0xff;
+       int min = (signed char)((kcontrol->private_value >> 24) & 0xff);
+       int val = snd_soc_read(codec, reg);
+
+       ucontrol->value.integer.value[0] =
+               ((signed char)(val & 0xff))-min;
+       ucontrol->value.integer.value[1] =
+               ((signed char)((val >> 8) & 0xff))-min;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_volsw_s8);
+
+/**
+ * snd_soc_put_volsw_sgn - signed mixer put callback
+ * @kcontrol: mixer control
+ * @uinfo: control element information
+ *
+ * Callback to set the value of a signed mixer control.
+ *
+ * Returns 0 for success.
+ */
+int snd_soc_put_volsw_s8(struct snd_kcontrol *kcontrol,
+       struct snd_ctl_elem_value *ucontrol)
+{
+       struct snd_soc_codec *codec = snd_kcontrol_chip(kcontrol);
+       int reg = kcontrol->private_value & 0xff;
+       int min = (signed char)((kcontrol->private_value >> 24) & 0xff);
+       unsigned short val;
+
+       val = (ucontrol->value.integer.value[0]+min) & 0xff;
+       val |= ((ucontrol->value.integer.value[1]+min) & 0xff) << 8;
+
+       return snd_soc_update_bits(codec, reg, 0xffff, val);
+}
+EXPORT_SYMBOL_GPL(snd_soc_put_volsw_s8);
+
 static int __devinit snd_soc_init(void)
 {
        printk(KERN_INFO "ASoC version %s\n", SND_SOC_VERSION);
@@ -1591,7 +1669,7 @@ static int __devinit snd_soc_init(void)
 
 static void snd_soc_exit(void)
 {
-       platform_driver_unregister(&soc_driver);
+       platform_driver_unregister(&soc_driver);
 }
 
 module_init(snd_soc_init);
@@ -1601,3 +1679,4 @@ module_exit(snd_soc_exit);
 MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
 MODULE_DESCRIPTION("ALSA SoC Core");
 MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:soc-audio");