[v2] ASoC: simple-card-utils: introduce asoc_simple_parse_triggers()
Commit Message
This function parses DT DAI link triggers params and assigns
the appropriate fields in struct snd_soc_dai_link.
It supports two triggers trigger-stop and trigger-start.
Signed-off-by: Maxim Kochetkov <fido_max@inbox.ru>
---
include/sound/simple_card_utils.h | 3 ++
sound/soc/generic/simple-card-utils.c | 45 +++++++++++++++++++++++++++
2 files changed, 48 insertions(+)
@@ -180,6 +180,9 @@ int asoc_simple_parse_widgets(struct snd_soc_card *card,
char *prefix);
int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
char *prefix);
+int asoc_simple_parse_triggers(struct device_node *node,
+ char *prefix,
+ struct snd_soc_dai_link *dai_link);
int asoc_simple_init_jack(struct snd_soc_card *card,
struct asoc_simple_jack *sjack,
@@ -737,6 +737,51 @@ int asoc_simple_parse_pin_switches(struct snd_soc_card *card,
}
EXPORT_SYMBOL_GPL(asoc_simple_parse_pin_switches);
+static enum snd_soc_trigger_order asoc_simple_parse_trigger(
+ struct device_node *node,
+ char *prefix,
+ char *trigger_name)
+{
+ enum snd_soc_trigger_order trigger = SND_SOC_TRIGGER_ORDER_DEFAULT;
+ struct {
+ char *name;
+ unsigned int val;
+ } of_trigger_table[] = {
+ { "default", SND_SOC_TRIGGER_ORDER_DEFAULT },
+ { "ldc", SND_SOC_TRIGGER_ORDER_LDC },
+ };
+ const char *str;
+ char prop[128];
+ int ret;
+
+ if (!prefix)
+ prefix = "";
+
+ snprintf(prop, sizeof(prop), "%s%s", prefix, trigger_name);
+
+ ret = of_property_read_string(node, prop, &str);
+ if (ret == 0) {
+ for (int i = 0; i < ARRAY_SIZE(of_trigger_table); i++) {
+ if (strcmp(str, of_trigger_table[i].name) == 0) {
+ trigger = of_trigger_table[i].val;
+ break;
+ }
+ }
+ }
+
+ return trigger;
+}
+
+int asoc_simple_parse_triggers(struct device_node *node,
+ char *prefix,
+ struct snd_soc_dai_link *dai_link)
+{
+ dai_link->trigger_stop = asoc_simple_parse_trigger(node, prefix, "trigger-stop");
+ dai_link->trigger_start = asoc_simple_parse_trigger(node, prefix, "trigger-start");
+ return 0;
+}
+EXPORT_SYMBOL_GPL(asoc_simple_parse_triggers);
+
int asoc_simple_init_jack(struct snd_soc_card *card,
struct asoc_simple_jack *sjack,
int is_hp, char *prefix,