diff mbox

[5/6,v3] ASoC: rsnd: enable enumerated DVC valume settings

Message ID 877fza46eq.wl%kuninori.morimoto.gx@gmail.com (mailing list archive)
State Accepted
Commit 018342976ce971944dd4d9309f75e86382079a2b
Headers show

Commit Message

Kuninori Morimoto Nov. 5, 2014, 4:28 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

DVC controls some digital volume features.
Volume Ramp is listed as "XX dB / YY steps",
and this enumerated settings are easy for users.
This patch adds rsnd_dvc_cfg_e and care about
enumerated settings.
Compiler will report like below at this point,
but, it will be removed if Volume Ramp was supported.
  warning: '_rsnd_dvc_pcm_new_e' defined but not used

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v2 -> v3

 - new patch

 sound/soc/sh/rcar/dvc.c |   55 +++++++++++++++++++++++++++++++++++++----------
 1 file changed, 44 insertions(+), 11 deletions(-)

Comments

Mark Brown Nov. 6, 2014, 5:05 p.m. UTC | #1
On Tue, Nov 04, 2014 at 08:28:50PM -0800, Kuninori Morimoto wrote:
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> DVC controls some digital volume features.
> Volume Ramp is listed as "XX dB / YY steps",
> and this enumerated settings are easy for users.

Applied, thanks.
diff mbox

Patch

diff --git a/sound/soc/sh/rcar/dvc.c b/sound/soc/sh/rcar/dvc.c
index e7cfc71..8504f6b 100644
--- a/sound/soc/sh/rcar/dvc.c
+++ b/sound/soc/sh/rcar/dvc.c
@@ -19,6 +19,7 @@  struct rsnd_dvc_cfg {
 	unsigned int max;
 	unsigned int size;
 	u32 *val;
+	const char * const *texts;
 };
 
 struct rsnd_dvc_cfg_m {
@@ -169,14 +170,23 @@  static int rsnd_dvc_volume_info(struct snd_kcontrol *kctrl,
 {
 	struct rsnd_dvc_cfg *cfg = (struct rsnd_dvc_cfg *)kctrl->private_value;
 
-	uinfo->count = cfg->size;
-	uinfo->value.integer.min = 0;
-	uinfo->value.integer.max = cfg->max;
-
-	if (cfg->max == 1)
-		uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-	else
-		uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
+	if (cfg->texts) {
+		uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
+		uinfo->count = cfg->size;
+		uinfo->value.enumerated.items = cfg->max;
+		if (uinfo->value.enumerated.item >= cfg->max)
+			uinfo->value.enumerated.item = cfg->max - 1;
+		strlcpy(uinfo->value.enumerated.name,
+			cfg->texts[uinfo->value.enumerated.item],
+			sizeof(uinfo->value.enumerated.name));
+	} else {
+		uinfo->count = cfg->size;
+		uinfo->value.integer.min = 0;
+		uinfo->value.integer.max = cfg->max;
+		uinfo->type = (cfg->max == 1) ?
+			SNDRV_CTL_ELEM_TYPE_BOOLEAN :
+			SNDRV_CTL_ELEM_TYPE_INTEGER;
+	}
 
 	return 0;
 }
@@ -188,7 +198,10 @@  static int rsnd_dvc_volume_get(struct snd_kcontrol *kctrl,
 	int i;
 
 	for (i = 0; i < cfg->size; i++)
-		ucontrol->value.integer.value[i] = cfg->val[i];
+		if (cfg->texts)
+			ucontrol->value.enumerated.item[i] = cfg->val[i];
+		else
+			ucontrol->value.integer.value[i] = cfg->val[i];
 
 	return 0;
 }
@@ -201,8 +214,13 @@  static int rsnd_dvc_volume_put(struct snd_kcontrol *kctrl,
 	int i, change = 0;
 
 	for (i = 0; i < cfg->size; i++) {
-		change |= (ucontrol->value.integer.value[i] != cfg->val[i]);
-		cfg->val[i] = ucontrol->value.integer.value[i];
+		if (cfg->texts) {
+			change |= (ucontrol->value.enumerated.item[i] != cfg->val[i]);
+			cfg->val[i] = ucontrol->value.enumerated.item[i];
+		} else {
+			change |= (ucontrol->value.integer.value[i] != cfg->val[i]);
+			cfg->val[i] = ucontrol->value.integer.value[i];
+		}
 	}
 
 	if (change)
@@ -266,6 +284,21 @@  static int _rsnd_dvc_pcm_new_s(struct rsnd_mod *mod,
 	return __rsnd_dvc_pcm_new(mod, rdai, rtd, name, &private->cfg);
 }
 
+static int _rsnd_dvc_pcm_new_e(struct rsnd_mod *mod,
+			       struct rsnd_dai *rdai,
+			       struct snd_soc_pcm_runtime *rtd,
+			       const unsigned char *name,
+			       struct rsnd_dvc_cfg_s *private,
+			       const char * const *texts,
+			       u32 max)
+{
+	private->cfg.max	= max;
+	private->cfg.size	= 1;
+	private->cfg.val	= &private->val;
+	private->cfg.texts	= texts;
+	return __rsnd_dvc_pcm_new(mod, rdai, rtd, name, &private->cfg);
+}
+
 static int rsnd_dvc_pcm_new(struct rsnd_mod *mod,
 			    struct rsnd_dai *rdai,
 			    struct snd_soc_pcm_runtime *rtd)