From patchwork Mon Mar 14 08:07:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liam Girdwood X-Patchwork-Id: 8577281 Return-Path: X-Original-To: patchwork-alsa-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 46FD5C0553 for ; Mon, 14 Mar 2016 08:10:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 36E9B2045A for ; Mon, 14 Mar 2016 08:10:22 +0000 (UTC) Received: from alsa0.perex.cz (alsa0.perex.cz [77.48.224.243]) by mail.kernel.org (Postfix) with ESMTP id BFB05203FB for ; Mon, 14 Mar 2016 08:10:20 +0000 (UTC) Received: by alsa0.perex.cz (Postfix, from userid 1000) id D28272652C1; Mon, 14 Mar 2016 09:10:19 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from alsa0.perex.cz (localhost [127.0.0.1]) by alsa0.perex.cz (Postfix) with ESMTP id D6016264F52; Mon, 14 Mar 2016 09:08:13 +0100 (CET) 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 1F710264F0D; Mon, 14 Mar 2016 09:08:12 +0100 (CET) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by alsa0.perex.cz (Postfix) with ESMTP id 0E268261507 for ; Mon, 14 Mar 2016 09:08:06 +0100 (CET) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga102.fm.intel.com with ESMTP; 14 Mar 2016 01:08:06 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,334,1455004800"; d="scan'208";a="909697401" Received: from sbianti-mobl.mp.intel.com (HELO loki.ger.corp.intel.com) ([10.252.24.40]) by orsmga001.jf.intel.com with ESMTP; 14 Mar 2016 01:08:05 -0700 From: Liam Girdwood To: Date: Mon, 14 Mar 2016 08:07:37 +0000 Message-Id: <1457942858-5652-4-git-send-email-liam.r.girdwood@linux.intel.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1457942858-5652-1-git-send-email-liam.r.girdwood@linux.intel.com> References: <1457942858-5652-1-git-send-email-liam.r.girdwood@linux.intel.com> Cc: Takashi Iwai , Liam Girdwood Subject: [alsa-devel] [PATCH] topology: add support for CTL access flags to config file 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 Allow the config files to define CTL access flags. Signed-off-by: Liam Girdwood --- include/topology.h | 29 ++++++++++++ src/topology/ctl.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 161 insertions(+), 4 deletions(-) diff --git a/include/topology.h b/include/topology.h index 993537c..011f6ae 100644 --- a/include/topology.h +++ b/include/topology.h @@ -93,6 +93,35 @@ extern "C" { * * range * * strobe * +*
Control Access
+ * Controls access can be specified using the "access" section. If no "access" + * section is defined then default RW access flags are set for normal and TLV + * controls. + * + *
+ *	access [
+ *		read
+ *		write
+ *		tlv_command
+ *	]
+ * 
+ * + * The standard access flags are as follows :- + * * read + * * write + * * read_write + * * volatile + * * timestamp + * * tlv_read + * * tlv_write + * * tlv_read_write + * * tlv_command + * * inactive + * * lock + * * owner + * * tlv_callback + * * user + * *
Control TLV Data
* Controls can also use TLV data to represent dB information. This can be done * by defining a TLV section and using the TLV section within the control. diff --git a/src/topology/ctl.c b/src/topology/ctl.c index 23c196a..b948ac0 100644 --- a/src/topology/ctl.c +++ b/src/topology/ctl.c @@ -21,6 +21,88 @@ #define ENUM_VAL_SIZE (SNDRV_CTL_ELEM_ID_NAME_MAXLEN >> 2) +struct ctl_access_elem { + const char *name; + unsigned int value; +}; + +/* CTL access strings and codes */ +static const struct ctl_access_elem ctl_access[] = { + {"read", SNDRV_CTL_ELEM_ACCESS_READ}, + {"write", SNDRV_CTL_ELEM_ACCESS_WRITE}, + {"read_write", SNDRV_CTL_ELEM_ACCESS_READWRITE}, + {"volatile", SNDRV_CTL_ELEM_ACCESS_VOLATILE}, + {"timestamp", SNDRV_CTL_ELEM_ACCESS_TIMESTAMP}, + {"tlv_read", SNDRV_CTL_ELEM_ACCESS_TLV_READ}, + {"tlv_write", SNDRV_CTL_ELEM_ACCESS_TLV_WRITE}, + {"tlv_read_write", SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE}, + {"tlv_command", SNDRV_CTL_ELEM_ACCESS_TLV_COMMAND}, + {"inactive", SNDRV_CTL_ELEM_ACCESS_INACTIVE}, + {"lock", SNDRV_CTL_ELEM_ACCESS_LOCK}, + {"owner", SNDRV_CTL_ELEM_ACCESS_OWNER}, + {"tlv_callback", SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK}, + {"user", SNDRV_CTL_ELEM_ACCESS_USER}, +}; + +/* find CTL access strings and conver to values */ +static int parse_access_values(snd_config_t *cfg, + struct snd_soc_tplg_ctl_hdr *hdr) +{ + snd_config_iterator_t i, next; + snd_config_t *n; + const char *value = NULL; + unsigned int j; + + tplg_dbg(" Access:\n"); + + snd_config_for_each(i, next, cfg) { + n = snd_config_iterator_entry(i); + + /* get value */ + if (snd_config_get_string(n, &value) < 0) + continue; + + /* match access value and set flags */ + for (j = 0; j < ARRAY_SIZE(ctl_access); j++) { + if (strcmp(value, ctl_access[j].name) == 0) { + hdr->access |= ctl_access[j].value; + tplg_dbg("\t%s\n", value); + break; + } + } + } + + return 0; +} + +/* Parse Access */ +int parse_access(snd_config_t *cfg, + struct snd_soc_tplg_ctl_hdr *hdr) +{ + snd_config_iterator_t i, next; + snd_config_t *n; + const char *id; + int err = 0; + + snd_config_for_each(i, next, cfg) { + + n = snd_config_iterator_entry(i); + if (snd_config_get_id(n, &id) < 0) + continue; + + if (strcmp(id, "access") == 0) { + err = parse_access_values(n, hdr); + if (err < 0) { + SNDERR("error: failed to parse access"); + return err; + } + continue; + } + } + + return err; +} + /* copy referenced TLV to the mixer control */ static int copy_tlv(struct tplg_elem *elem, struct tplg_elem *ref) { @@ -295,6 +377,7 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg, snd_config_t *n; const char *id, *val = NULL; int err; + bool access_set = false, tlv_set = false; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_BYTES); if (!elem) @@ -380,8 +463,7 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg, if (err < 0) return err; - be->hdr.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | - SNDRV_CTL_ELEM_ACCESS_READWRITE; + tlv_set = true; tplg_dbg("\t%s: %s\n", id, val); continue; } @@ -401,6 +483,22 @@ int tplg_parse_control_bytes(snd_tplg_t *tplg, return err; continue; } + + if (strcmp(id, "access") == 0) { + err = parse_access(cfg, &be->hdr); + if (err < 0) + return err; + access_set = true; + continue; + } + } + + /* set CTL access to default values if none are provided */ + if (!access_set) { + + be->hdr.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; + if (tlv_set) + be->hdr.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; } return 0; @@ -416,6 +514,7 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, snd_config_t *n; const char *id, *val = NULL; int err, j; + bool access_set = false; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_ENUM); if (!elem) @@ -495,6 +594,19 @@ int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, tplg_dbg("\t%s: %s\n", id, val); continue; } + + if (strcmp(id, "access") == 0) { + err = parse_access(cfg, &ec->hdr); + if (err < 0) + return err; + access_set = true; + continue; + } + } + + /* set CTL access to default values if none are provided */ + if (!access_set) { + ec->hdr.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; } return 0; @@ -513,6 +625,7 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg, snd_config_t *n; const char *id, *val = NULL; int err, j; + bool access_set = false, tlv_set = false; elem = tplg_elem_new_common(tplg, cfg, NULL, SND_TPLG_TYPE_MIXER); if (!elem) @@ -606,8 +719,7 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg, if (err < 0) return err; - mc->hdr.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | - SNDRV_CTL_ELEM_ACCESS_READWRITE; + tlv_set = true; tplg_dbg("\t%s: %s\n", id, val); continue; } @@ -620,6 +732,22 @@ int tplg_parse_control_mixer(snd_tplg_t *tplg, tplg_dbg("\t%s: %s\n", id, val); continue; } + + if (strcmp(id, "access") == 0) { + err = parse_access(cfg, &mc->hdr); + if (err < 0) + return err; + access_set = true; + continue; + } + } + + /* set CTL access to default values if none are provided */ + if (!access_set) { + + mc->hdr.access = SNDRV_CTL_ELEM_ACCESS_READWRITE; + if (tlv_set) + mc->hdr.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; } return 0;