]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - sound/soc/soc-core.c
Merge tag 'selinux-pr-20171113' of git://git.kernel.org/pub/scm/linux/kernel/git...
[mirror_ubuntu-bionic-kernel.git] / sound / soc / soc-core.c
index faed564670cd3b159470968ed59ada6a8cc3e599..c0edac80df34e683291cff5fb86c560ee8e22ffd 100644 (file)
@@ -2800,7 +2800,7 @@ EXPORT_SYMBOL_GPL(snd_soc_dai_set_bclk_ratio);
 /**
  * snd_soc_dai_set_fmt - configure DAI hardware audio format.
  * @dai: DAI
- * @fmt: SND_SOC_DAIFMT_ format value.
+ * @fmt: SND_SOC_DAIFMT_* format value.
  *
  * Configures the DAI hardware format and clocking.
  */
@@ -3270,6 +3270,14 @@ static void snd_soc_component_drv_pcm_free(struct snd_soc_component *component,
                component->driver->pcm_free(pcm);
 }
 
+static int snd_soc_component_set_bias_level(struct snd_soc_dapm_context *dapm,
+                                       enum snd_soc_bias_level level)
+{
+       struct snd_soc_component *component = dapm->component;
+
+       return component->driver->set_bias_level(component, level);
+}
+
 static int snd_soc_component_initialize(struct snd_soc_component *component,
        const struct snd_soc_component_driver *driver, struct device *dev)
 {
@@ -3297,11 +3305,14 @@ static int snd_soc_component_initialize(struct snd_soc_component *component,
        dapm->dev = dev;
        dapm->component = component;
        dapm->bias_level = SND_SOC_BIAS_OFF;
-       dapm->idle_bias_off = true;
+       dapm->idle_bias_off = !driver->idle_bias_on;
+       dapm->suspend_bias_off = driver->suspend_bias_off;
        if (driver->seq_notifier)
                dapm->seq_notifier = snd_soc_component_seq_notifier;
        if (driver->stream_event)
                dapm->stream_event = snd_soc_component_stream_event;
+       if (driver->set_bias_level)
+               dapm->set_bias_level = snd_soc_component_set_bias_level;
 
        INIT_LIST_HEAD(&component->dai_list);
        mutex_init(&component->io_mutex);
@@ -3393,19 +3404,49 @@ static void snd_soc_component_del_unlocked(struct snd_soc_component *component)
        list_del(&component->list);
 }
 
-int snd_soc_register_component(struct device *dev,
-                              const struct snd_soc_component_driver *component_driver,
-                              struct snd_soc_dai_driver *dai_drv,
-                              int num_dai)
+#define ENDIANNESS_MAP(name) \
+       (SNDRV_PCM_FMTBIT_##name##LE | SNDRV_PCM_FMTBIT_##name##BE)
+static u64 endianness_format_map[] = {
+       ENDIANNESS_MAP(S16_),
+       ENDIANNESS_MAP(U16_),
+       ENDIANNESS_MAP(S24_),
+       ENDIANNESS_MAP(U24_),
+       ENDIANNESS_MAP(S32_),
+       ENDIANNESS_MAP(U32_),
+       ENDIANNESS_MAP(S24_3),
+       ENDIANNESS_MAP(U24_3),
+       ENDIANNESS_MAP(S20_3),
+       ENDIANNESS_MAP(U20_3),
+       ENDIANNESS_MAP(S18_3),
+       ENDIANNESS_MAP(U18_3),
+       ENDIANNESS_MAP(FLOAT_),
+       ENDIANNESS_MAP(FLOAT64_),
+       ENDIANNESS_MAP(IEC958_SUBFRAME_),
+};
+
+/*
+ * Fix up the DAI formats for endianness: codecs don't actually see
+ * the endianness of the data but we're using the CPU format
+ * definitions which do need to include endianness so we ensure that
+ * codec DAIs always have both big and little endian variants set.
+ */
+static void convert_endianness_formats(struct snd_soc_pcm_stream *stream)
 {
-       struct snd_soc_component *component;
-       int ret;
+       int i;
 
-       component = kzalloc(sizeof(*component), GFP_KERNEL);
-       if (!component) {
-               dev_err(dev, "ASoC: Failed to allocate memory\n");
-               return -ENOMEM;
-       }
+       for (i = 0; i < ARRAY_SIZE(endianness_format_map); i++)
+               if (stream->formats & endianness_format_map[i])
+                       stream->formats |= endianness_format_map[i];
+}
+
+int snd_soc_add_component(struct device *dev,
+                       struct snd_soc_component *component,
+                       const struct snd_soc_component_driver *component_driver,
+                       struct snd_soc_dai_driver *dai_drv,
+                       int num_dai)
+{
+       int ret;
+       int i;
 
        ret = snd_soc_component_initialize(component, component_driver, dev);
        if (ret)
@@ -3414,7 +3455,15 @@ int snd_soc_register_component(struct device *dev,
        component->ignore_pmdown_time = true;
        component->registered_as_component = true;
 
-       ret = snd_soc_register_dais(component, dai_drv, num_dai, true);
+       if (component_driver->endianness) {
+               for (i = 0; i < num_dai; i++) {
+                       convert_endianness_formats(&dai_drv[i].playback);
+                       convert_endianness_formats(&dai_drv[i].capture);
+               }
+       }
+
+       ret = snd_soc_register_dais(component, dai_drv, num_dai,
+                                   !component_driver->non_legacy_dai_naming);
        if (ret < 0) {
                dev_err(dev, "ASoC: Failed to register DAIs: %d\n", ret);
                goto err_cleanup;
@@ -3430,6 +3479,22 @@ err_free:
        kfree(component);
        return ret;
 }
+EXPORT_SYMBOL_GPL(snd_soc_add_component);
+
+int snd_soc_register_component(struct device *dev,
+                       const struct snd_soc_component_driver *component_driver,
+                       struct snd_soc_dai_driver *dai_drv,
+                       int num_dai)
+{
+       struct snd_soc_component *component;
+
+       component = kzalloc(sizeof(*component), GFP_KERNEL);
+       if (!component)
+               return -ENOMEM;
+
+       return snd_soc_add_component(dev, component, component_driver,
+                                    dai_drv, num_dai);
+}
 EXPORT_SYMBOL_GPL(snd_soc_register_component);
 
 /**
@@ -3470,6 +3535,32 @@ void snd_soc_unregister_component(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(snd_soc_unregister_component);
 
+struct snd_soc_component *snd_soc_lookup_component(struct device *dev,
+                                                  const char *driver_name)
+{
+       struct snd_soc_component *component;
+       struct snd_soc_component *ret;
+
+       ret = NULL;
+       mutex_lock(&client_mutex);
+       list_for_each_entry(component, &component_list, list) {
+               if (dev != component->dev)
+                       continue;
+
+               if (driver_name &&
+                   (driver_name != component->driver->name) &&
+                   (strcmp(component->driver->name, driver_name) != 0))
+                       continue;
+
+               ret = component;
+               break;
+       }
+       mutex_unlock(&client_mutex);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(snd_soc_lookup_component);
+
 static int snd_soc_platform_drv_probe(struct snd_soc_component *component)
 {
        struct snd_soc_platform *platform = snd_soc_component_to_platform(component);
@@ -3628,39 +3719,6 @@ void snd_soc_unregister_platform(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(snd_soc_unregister_platform);
 
-static u64 codec_format_map[] = {
-       SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE,
-       SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE,
-       SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE,
-       SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE,
-       SNDRV_PCM_FMTBIT_S32_LE | SNDRV_PCM_FMTBIT_S32_BE,
-       SNDRV_PCM_FMTBIT_U32_LE | SNDRV_PCM_FMTBIT_U32_BE,
-       SNDRV_PCM_FMTBIT_S24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
-       SNDRV_PCM_FMTBIT_U24_3LE | SNDRV_PCM_FMTBIT_U24_3BE,
-       SNDRV_PCM_FMTBIT_S20_3LE | SNDRV_PCM_FMTBIT_S20_3BE,
-       SNDRV_PCM_FMTBIT_U20_3LE | SNDRV_PCM_FMTBIT_U20_3BE,
-       SNDRV_PCM_FMTBIT_S18_3LE | SNDRV_PCM_FMTBIT_S18_3BE,
-       SNDRV_PCM_FMTBIT_U18_3LE | SNDRV_PCM_FMTBIT_U18_3BE,
-       SNDRV_PCM_FMTBIT_FLOAT_LE | SNDRV_PCM_FMTBIT_FLOAT_BE,
-       SNDRV_PCM_FMTBIT_FLOAT64_LE | SNDRV_PCM_FMTBIT_FLOAT64_BE,
-       SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_LE
-       | SNDRV_PCM_FMTBIT_IEC958_SUBFRAME_BE,
-};
-
-/* Fix up the DAI formats for endianness: codecs don't actually see
- * the endianness of the data but we're using the CPU format
- * definitions which do need to include endianness so we ensure that
- * codec DAIs always have both big and little endian variants set.
- */
-static void fixup_codec_formats(struct snd_soc_pcm_stream *stream)
-{
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(codec_format_map); i++)
-               if (stream->formats & codec_format_map[i])
-                       stream->formats |= codec_format_map[i];
-}
-
 static int snd_soc_codec_drv_probe(struct snd_soc_component *component)
 {
        struct snd_soc_codec *codec = snd_soc_component_to_codec(component);
@@ -3811,8 +3869,8 @@ int snd_soc_register_codec(struct device *dev,
                codec->component.regmap = codec_drv->get_regmap(dev);
 
        for (i = 0; i < num_dai; i++) {
-               fixup_codec_formats(&dai_drv[i].playback);
-               fixup_codec_formats(&dai_drv[i].capture);
+               convert_endianness_formats(&dai_drv[i].playback);
+               convert_endianness_formats(&dai_drv[i].capture);
        }
 
        ret = snd_soc_register_dais(&codec->component, dai_drv, num_dai, false);