All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Mack <daniel@zonque.org>
To: alsa-devel@alsa-project.org
Cc: tiwai@suse.de, broonie@kernel.org, Daniel Mack <daniel@zonque.org>
Subject: [alsa-devel] [PATCH 1/2] ALSA: core: add snd_pcm_format_by_name()
Date: Thu,  5 Dec 2019 09:14:27 +0100	[thread overview]
Message-ID: <20191205081428.611572-1-daniel@zonque.org> (raw)

Add a new function to look up PCM format codes by name. This can be used
by ASoC drivers to look up formats through device-tree properties, for
instance.

Signed-off-by: Daniel Mack <daniel@zonque.org>
---
 include/sound/pcm.h |  1 +
 sound/core/pcm.c    | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index bbe6eb1ff5d2..ce398caf12ba 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -1339,6 +1339,7 @@ static inline void snd_pcm_limit_isa_dma_size(int dma, size_t *max)
 #define PCM_RUNTIME_CHECK(sub) snd_BUG_ON(!(sub) || !(sub)->runtime)
 
 const char *snd_pcm_format_name(snd_pcm_format_t format);
+snd_pcm_format_t snd_pcm_format_by_name(const char *name);
 
 /**
  * snd_pcm_stream_str - Get a string naming the direction of a stream
diff --git a/sound/core/pcm.c b/sound/core/pcm.c
index 9a72d641743d..248f2dca7a12 100644
--- a/sound/core/pcm.c
+++ b/sound/core/pcm.c
@@ -225,6 +225,18 @@ const char *snd_pcm_format_name(snd_pcm_format_t format)
 }
 EXPORT_SYMBOL_GPL(snd_pcm_format_name);
 
+snd_pcm_format_t snd_pcm_format_by_name(const char *name)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(snd_pcm_format_names); i++)
+		if (strcasecmp(name, snd_pcm_format_names[i]) == 0)
+			return i;
+
+	return -ENOENT;
+}
+EXPORT_SYMBOL_GPL(snd_pcm_format_by_name);
+
 #ifdef CONFIG_SND_VERBOSE_PROCFS
 
 #define STATE(v) [SNDRV_PCM_STATE_##v] = #v
-- 
2.23.0

_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

             reply	other threads:[~2019-12-05  8:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-05  8:14 Daniel Mack [this message]
2019-12-05  8:14 ` [alsa-devel] [PATCH 2/2] ASoC: simple-card: add support for codec-to-codec links Daniel Mack
2019-12-05  9:18   ` Mark Brown
2019-12-05  8:25 ` [alsa-devel] [PATCH 1/2] ALSA: core: add snd_pcm_format_by_name() Takashi Iwai
2019-12-05  9:21   ` Daniel Mack

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191205081428.611572-1-daniel@zonque.org \
    --to=daniel@zonque.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@kernel.org \
    --cc=tiwai@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.