ASoC: simple-card: add support for aux devices
[cascardo/linux.git] / sound / soc / generic / simple-card.c
index fe0bc5c..f608f8d 100644 (file)
@@ -318,6 +318,36 @@ dai_link_of_err:
        return ret;
 }
 
+static int asoc_simple_card_parse_aux_devs(struct device_node *node,
+                                          struct simple_card_data *priv)
+{
+       struct device *dev = simple_priv_to_dev(priv);
+       struct device_node *aux_node;
+       int i, n, len;
+
+       if (!of_find_property(node, PREFIX "aux-devs", &len))
+               return 0;               /* Ok to have no aux-devs */
+
+       n = len / sizeof(__be32);
+       if (n <= 0)
+               return -EINVAL;
+
+       priv->snd_card.aux_dev = devm_kzalloc(dev,
+                       n * sizeof(*priv->snd_card.aux_dev), GFP_KERNEL);
+       if (!priv->snd_card.aux_dev)
+               return -ENOMEM;
+
+       for (i = 0; i < n; i++) {
+               aux_node = of_parse_phandle(node, PREFIX "aux-devs", i);
+               if (!aux_node)
+                       return -EINVAL;
+               priv->snd_card.aux_dev[i].codec_of_node = aux_node;
+       }
+
+       priv->snd_card.num_aux_devs = n;
+       return 0;
+}
+
 static int asoc_simple_card_parse_of(struct device_node *node,
                                     struct simple_card_data *priv)
 {
@@ -372,6 +402,10 @@ static int asoc_simple_card_parse_of(struct device_node *node,
        }
 
        ret = asoc_simple_card_parse_card_name(&priv->snd_card, PREFIX);
+       if (ret < 0)
+               goto card_parse_end;
+
+       ret = asoc_simple_card_parse_aux_devs(node, priv);
 
 card_parse_end:
        of_node_put(dai_link);