Blame src/topology/ops.c

Packit 4a16fb
/*
Packit 4a16fb
  Copyright(c) 2014-2015 Intel Corporation
Packit 4a16fb
  All rights reserved.
Packit 4a16fb
Packit 4a16fb
  This library is free software; you can redistribute it and/or modify
Packit 4a16fb
  it under the terms of the GNU Lesser General Public License as
Packit 4a16fb
  published by the Free Software Foundation; either version 2.1 of
Packit 4a16fb
  the License, or (at your option) any later version.
Packit 4a16fb
Packit 4a16fb
  This program is distributed in the hope that it will be useful,
Packit 4a16fb
  but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4a16fb
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 4a16fb
  GNU Lesser General Public License for more details.
Packit 4a16fb
Packit 4a16fb
  Authors: Mengdong Lin <mengdong.lin@intel.com>
Packit 4a16fb
           Yao Jin <yao.jin@intel.com>
Packit 4a16fb
           Liam Girdwood <liam.r.girdwood@linux.intel.com>
Packit 4a16fb
*/
Packit 4a16fb
Packit 4a16fb
#include "list.h"
Packit 4a16fb
#include "tplg_local.h"
Packit 4a16fb
Packit 4a16fb
/* mapping of kcontrol text names to types */
Packit 4a16fb
static const struct map_elem control_map[] = {
Packit 4a16fb
	{"volsw", SND_SOC_TPLG_CTL_VOLSW},
Packit 4a16fb
	{"volsw_sx", SND_SOC_TPLG_CTL_VOLSW_SX},
Packit 4a16fb
	{"volsw_xr_sx", SND_SOC_TPLG_CTL_VOLSW_XR_SX},
Packit 4a16fb
	{"enum", SND_SOC_TPLG_CTL_ENUM},
Packit 4a16fb
	{"bytes", SND_SOC_TPLG_CTL_BYTES},
Packit 4a16fb
	{"enum_value", SND_SOC_TPLG_CTL_ENUM_VALUE},
Packit 4a16fb
	{"range", SND_SOC_TPLG_CTL_RANGE},
Packit 4a16fb
	{"strobe", SND_SOC_TPLG_CTL_STROBE},
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
static int lookup_ops(const char *c)
Packit 4a16fb
{
Packit 4a16fb
	unsigned int i;
Packit 4a16fb
Packit 4a16fb
	for (i = 0; i < ARRAY_SIZE(control_map); i++) {
Packit 4a16fb
		if (strcmp(control_map[i].name, c) == 0)
Packit 4a16fb
			return control_map[i].id;
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	/* cant find string name in our table so we use its ID number */
Packit 4a16fb
	return atoi(c);
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/* Parse Control operations. Ops can come from standard names above or
Packit 4a16fb
 * bespoke driver controls with numbers >= 256
Packit 4a16fb
 */
Packit 4a16fb
int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
Packit 4a16fb
	snd_config_t *cfg, void *private)
Packit 4a16fb
{
Packit 4a16fb
	snd_config_iterator_t i, next;
Packit 4a16fb
	snd_config_t *n;
Packit 4a16fb
	struct snd_soc_tplg_ctl_hdr *hdr = private;
Packit 4a16fb
	const char *id, *value;
Packit 4a16fb
Packit 4a16fb
	tplg_dbg("\tOps\n");
Packit 4a16fb
	hdr->size = sizeof(*hdr);
Packit 4a16fb
Packit 4a16fb
	snd_config_for_each(i, next, cfg) {
Packit 4a16fb
Packit 4a16fb
		n = snd_config_iterator_entry(i);
Packit 4a16fb
Packit 4a16fb
		/* get id */
Packit 4a16fb
		if (snd_config_get_id(n, &id) < 0)
Packit 4a16fb
			continue;
Packit 4a16fb
Packit 4a16fb
		/* get value - try strings then ints */
Packit 4a16fb
		if (snd_config_get_string(n, &value) < 0)
Packit 4a16fb
			continue;
Packit 4a16fb
Packit 4a16fb
		if (strcmp(id, "info") == 0)
Packit 4a16fb
			hdr->ops.info = lookup_ops(value);
Packit 4a16fb
		else if (strcmp(id, "put") == 0)
Packit 4a16fb
			hdr->ops.put = lookup_ops(value);
Packit 4a16fb
		else if (strcmp(id, "get") == 0)
Packit 4a16fb
			hdr->ops.get = lookup_ops(value);
Packit 4a16fb
Packit 4a16fb
		tplg_dbg("\t\t%s = %s\n", id, value);
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	return 0;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/* Parse External Control operations. Ops can come from standard names above or
Packit 4a16fb
 * bespoke driver controls with numbers >= 256
Packit 4a16fb
 */
Packit 4a16fb
int tplg_parse_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
Packit 4a16fb
	snd_config_t *cfg, void *private)
Packit 4a16fb
{
Packit 4a16fb
	snd_config_iterator_t i, next;
Packit 4a16fb
	snd_config_t *n;
Packit 4a16fb
	struct snd_soc_tplg_bytes_control *be = private;
Packit 4a16fb
	const char *id, *value;
Packit 4a16fb
Packit 4a16fb
	tplg_dbg("\tExt Ops\n");
Packit 4a16fb
Packit 4a16fb
	snd_config_for_each(i, next, cfg) {
Packit 4a16fb
Packit 4a16fb
		n = snd_config_iterator_entry(i);
Packit 4a16fb
Packit 4a16fb
		/* get id */
Packit 4a16fb
		if (snd_config_get_id(n, &id) < 0)
Packit 4a16fb
			continue;
Packit 4a16fb
Packit 4a16fb
		/* get value - try strings then ints */
Packit 4a16fb
		if (snd_config_get_string(n, &value) < 0)
Packit 4a16fb
			continue;
Packit 4a16fb
Packit 4a16fb
		if (strcmp(id, "info") == 0)
Packit 4a16fb
			be->ext_ops.info = lookup_ops(value);
Packit 4a16fb
		else if (strcmp(id, "put") == 0)
Packit 4a16fb
			be->ext_ops.put = lookup_ops(value);
Packit 4a16fb
		else if (strcmp(id, "get") == 0)
Packit 4a16fb
			be->ext_ops.get = lookup_ops(value);
Packit 4a16fb
Packit 4a16fb
		tplg_dbg("\t\t%s = %s\n", id, value);
Packit 4a16fb
	}
Packit 4a16fb
Packit 4a16fb
	return 0;
Packit 4a16fb
}