From patchwork Wed Jul 29 16:45:17 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Girdwood X-Patchwork-Id: 6895391 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0B8169F39D for ; Wed, 29 Jul 2015 16:48:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id BED86201FE for ; Wed, 29 Jul 2015 16:48:06 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id 067D62013D for ; Wed, 29 Jul 2015 16:48:01 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id 0FCAA265D1C; Wed, 29 Jul 2015 18:48:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [IPv6:::1]) by alsa0.perex.cz (Postfix) with ESMTP id E69A5265A66; Wed, 29 Jul 2015 18:46:15 +0200 (CEST) X-Original-To: alsa-devel@alsa-project.org Delivered-To: alsa-devel@alsa-project.org Received: by alsa0.perex.cz (Postfix, from userid 1000) id 51F0A265A46; Wed, 29 Jul 2015 18:46:14 +0200 (CEST) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by alsa0.perex.cz (Postfix) with ESMTP id 37A25260644 for ; Wed, 29 Jul 2015 18:45:51 +0200 (CEST) Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga103.fm.intel.com with ESMTP; 29 Jul 2015 09:45:51 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,572,1432623600"; d="scan'208";a="615321017" Received: from iikavana-mobl1.ger.corp.intel.com (HELO loki.ger.corp.intel.com) ([10.252.21.221]) by orsmga003.jf.intel.com with ESMTP; 29 Jul 2015 09:45:49 -0700 From: Liam Girdwood To: Date: Wed, 29 Jul 2015 17:45:17 +0100 Message-Id: <1438188325-11553-6-git-send-email-liam.r.girdwood@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1438188325-11553-1-git-send-email-liam.r.girdwood@linux.intel.com> References: <1438188325-11553-1-git-send-email-liam.r.girdwood@linux.intel.com> Cc: Takashi Iwai , Liam Girdwood , Mark Brown Subject: [alsa-devel] [PATCH v3 05/13] topology: Add operations parser X-BeenThere: alsa-devel@alsa-project.org X-Mailman-Version: 2.1.14 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: , MIME-Version: 1.0 Errors-To: alsa-devel-bounces@alsa-project.org Sender: alsa-devel-bounces@alsa-project.org X-Virus-Scanned: ClamAV using ClamSMTP Parse operations so we can bind them to kcontrols in the kernel. Signed-off-by: Liam Girdwood --- src/topology/ops.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/topology/ops.c diff --git a/src/topology/ops.c b/src/topology/ops.c new file mode 100644 index 0000000..243d8c5 --- /dev/null +++ b/src/topology/ops.c @@ -0,0 +1,84 @@ +/* + Copyright(c) 2014-2015 Intel Corporation + All rights reserved. + + This program is free software; you can redistribute it and/or modify + it under the terms of version 2 of the GNU General Public License as + published by the Free Software Foundation. + + This program is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + Authors: Mengdong Lin + Yao Jin + Liam Girdwood +*/ + +#include "list.h" +#include "tplg_local.h" + +/* mapping of kcontrol text names to types */ +static const struct map_elem control_map[] = { + {"volsw", SND_SOC_TPLG_CTL_VOLSW}, + {"volsw_sx", SND_SOC_TPLG_CTL_VOLSW_SX}, + {"volsw_xr_sx", SND_SOC_TPLG_CTL_VOLSW_XR_SX}, + {"enum", SND_SOC_TPLG_CTL_ENUM}, + {"bytes", SND_SOC_TPLG_CTL_BYTES}, + {"enum_value", SND_SOC_TPLG_CTL_ENUM_VALUE}, + {"range", SND_SOC_TPLG_CTL_RANGE}, + {"strobe", SND_SOC_TPLG_CTL_STROBE}, +}; + +static int lookup_ops(const char *c) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(control_map); i++) { + if (strcmp(control_map[i].name, c) == 0) + return control_map[i].id; + } + + /* cant find string name in our table so we use its ID number */ + return atoi(c); +} + +/* Parse Control operations. Ops can come from standard names above or + * bespoke driver controls with numbers >= 256 + */ +int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED, + snd_config_t *cfg, void *private) +{ + snd_config_iterator_t i, next; + snd_config_t *n; + struct snd_soc_tplg_ctl_hdr *hdr = private; + const char *id, *value; + + tplg_dbg("\tOps\n"); + hdr->size = sizeof(*hdr); + + snd_config_for_each(i, next, cfg) { + + n = snd_config_iterator_entry(i); + + /* get id */ + if (snd_config_get_id(n, &id) < 0) + continue; + + /* get value - try strings then ints */ + if (snd_config_get_string(n, &value) < 0) + continue; + + if (strcmp(id, "info") == 0) + hdr->ops.info = lookup_ops(value); + else if (strcmp(id, "put") == 0) + hdr->ops.put = lookup_ops(value); + else if (strcmp(id, "get") == 0) + hdr->ops.get = lookup_ops(value); + + tplg_dbg("\t\t%s = %s\n", id, value); + } + + return 0; +}