ASoC: simple-card-utils: create jack inputs for aux_devs
[sfrench/cifs-2.6.git] / sound / soc / generic / simple-card-utils.c
index e35becce9635f776a5506220c4890c351ed5ec83..56552a616f21ff066d09ebdf4490139f454407c1 100644 (file)
@@ -786,6 +786,55 @@ int asoc_simple_init_jack(struct snd_soc_card *card,
 }
 EXPORT_SYMBOL_GPL(asoc_simple_init_jack);
 
+int asoc_simple_init_aux_jacks(struct asoc_simple_priv *priv, char *prefix)
+{
+       struct snd_soc_card *card = simple_priv_to_card(priv);
+       struct snd_soc_component *component;
+       int found_jack_index = 0;
+       int type = 0;
+       int num = 0;
+       int ret;
+
+       if (priv->aux_jacks)
+               return 0;
+
+       for_each_card_auxs(card, component) {
+               type = snd_soc_component_get_jack_type(component);
+               if (type > 0)
+                       num++;
+       }
+       if (num < 1)
+               return 0;
+
+       priv->aux_jacks = devm_kcalloc(card->dev, num,
+                                      sizeof(struct snd_soc_jack), GFP_KERNEL);
+       if (!priv->aux_jacks)
+               return -ENOMEM;
+
+       for_each_card_auxs(card, component) {
+               char id[128];
+               struct snd_soc_jack *jack;
+
+               if (found_jack_index >= num)
+                       break;
+
+               type = snd_soc_component_get_jack_type(component);
+               if (type <= 0)
+                       continue;
+
+               /* create jack */
+               jack = &(priv->aux_jacks[found_jack_index++]);
+               snprintf(id, sizeof(id), "%s-jack", component->name);
+               ret = snd_soc_card_jack_new(card, id, type, jack);
+               if (ret)
+                       continue;
+
+               (void)snd_soc_component_set_jack(component, jack, NULL);
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(asoc_simple_init_aux_jacks);
+
 int asoc_simple_init_priv(struct asoc_simple_priv *priv,
                          struct link_info *li)
 {