From patchwork Thu Dec 5 09:21:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Mack X-Patchwork-Id: 11274375 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E64514B7 for ; Thu, 5 Dec 2019 09:24:17 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 18CC224652 for ; Thu, 5 Dec 2019 09:24:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=alsa-project.org header.i=@alsa-project.org header.b="j1ZqrFDb" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 18CC224652 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=zonque.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=alsa-devel-bounces@alsa-project.org Received: from alsa1.perex.cz (alsa1.perex.cz [207.180.221.201]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by alsa0.perex.cz (Postfix) with ESMTPS id 58392167C; Thu, 5 Dec 2019 10:23:25 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa0.perex.cz 58392167C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=alsa-project.org; s=default; t=1575537855; bh=lOYQJjhYSIdTJelylqGIChSSL3Ul9JESRtq7hqtAVxk=; h=From:To:Date:Cc:Subject:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From; b=j1ZqrFDbJJsQDcSP2vBmi3onsBXnfuEUti8/zrmXPWltWjYe7abrBPeybVP8aoSOd SZ/YGbmhtmG6GI9szBevzGjFpXOqcK6xoSMu7tCN7y7hRa3fe09k22FiCxuBx7dqYd wo0+fkEH1igVXK1j+UcWjIp0GnjbqpZFShjLky9U= Received: from alsa1.perex.cz (localhost.localdomain [127.0.0.1]) by alsa1.perex.cz (Postfix) with ESMTP id A649DF80256; Thu, 5 Dec 2019 10:21:44 +0100 (CET) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa1.perex.cz (Postfix, from userid 50401) id 51DF3F80252; Thu, 5 Dec 2019 10:21:43 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on alsa1.perex.cz X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=SPF_HELO_NONE,SPF_PASS, SURBL_BLOCKED,URIBL_BLOCKED autolearn=disabled version=3.4.0 Received: from mail.bugwerft.de (mail.bugwerft.de [IPv6:2a03:6000:1011::59]) by alsa1.perex.cz (Postfix) with ESMTP id 9FDE4F80228 for ; Thu, 5 Dec 2019 10:21:39 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 alsa1.perex.cz 9FDE4F80228 Received: from zenbar.localdomain (unknown [194.162.236.226]) by mail.bugwerft.de (Postfix) with ESMTPSA id 13F672E4FA3; Thu, 5 Dec 2019 09:15:26 +0000 (UTC) From: Daniel Mack To: alsa-devel@alsa-project.org Date: Thu, 5 Dec 2019 10:21:28 +0100 Message-Id: <20191205092129.692520-1-daniel@zonque.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Cc: tiwai@suse.de, broonie@kernel.org, Daniel Mack Subject: [alsa-devel] [PATCH v2 1/2] ALSA: core: add snd_pcm_format_by_name() X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: "Alsa-devel mailing list for ALSA developers - http://www.alsa-project.org" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: alsa-devel-bounces@alsa-project.org Sender: "Alsa-devel" 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 Reported-by: kbuild test robot --- include/sound/pcm.h | 1 + sound/core/pcm.c | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/include/sound/pcm.h b/include/sound/pcm.h index 8a89fa6fdd5e..1bfde6f2f180 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) (IEC958_AES3_CON_FS_48000<<24)) const char *snd_pcm_format_name(snd_pcm_format_t format); +int snd_pcm_format_by_name(const char *name, snd_pcm_format_t *format); /** * 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..c02d8df4f92b 100644 --- a/sound/core/pcm.c +++ b/sound/core/pcm.c @@ -225,6 +225,29 @@ const char *snd_pcm_format_name(snd_pcm_format_t format) } EXPORT_SYMBOL_GPL(snd_pcm_format_name); +/** + * snd_pcm_format_by_name - Return the PCM format code for the given name + * @name: PCM format name ('S16_LE', 'S24_3LE', ...) + * @format: Pointer to returned PCM format code + * + * The string comparison is done in a case-insensitive way. + * + * Return: 0 on success, or -ENOENT if the given format is not valid. + */ +int snd_pcm_format_by_name(const char *name, snd_pcm_format_t *format) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(snd_pcm_format_names); i++) + if (strcasecmp(name, snd_pcm_format_names[i]) == 0) { + *format = i; + return 0; + } + + return -ENOENT; +} +EXPORT_SYMBOL_GPL(snd_pcm_format_by_name); + #ifdef CONFIG_SND_VERBOSE_PROCFS #define STATE(v) [SNDRV_PCM_STATE_##v] = #v