alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] ALSA: Add snd_ctl_activate_id()
@ 2011-03-09 20:03 Mark Brown
  2011-03-10  6:52 ` Takashi Iwai
  0 siblings, 1 reply; 3+ messages in thread
From: Mark Brown @ 2011-03-09 20:03 UTC (permalink / raw)
  Cc: Takashi Iwai, alsa-devel, Mark Brown

From: Takashi Iwai <tiwai@suse.de>

Added a new API function snd_ctl_activate_id() for activate / inactivate
the control element dynamically.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
---

You wrote this patch a long time ago now - I'm currently working on a
driver which I think can make use if it.  Is it OK if I cherry-pick it
over into my code and push it through the ASoC branch if I do so?  Or
if you could merge it in the coming merge window, but there's a risk I
may come up with another way of doing things that doesn't need it.

 include/sound/control.h |    2 ++
 sound/core/control.c    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 0 deletions(-)

diff --git a/include/sound/control.h b/include/sound/control.h
index 7715e6f..e67db28 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -115,6 +115,8 @@ int snd_ctl_add(struct snd_card * card, struct snd_kcontrol * kcontrol);
 int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol);
 int snd_ctl_remove_id(struct snd_card * card, struct snd_ctl_elem_id *id);
 int snd_ctl_rename_id(struct snd_card * card, struct snd_ctl_elem_id *src_id, struct snd_ctl_elem_id *dst_id);
+int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id,
+			int active);
 struct snd_kcontrol *snd_ctl_find_numid(struct snd_card * card, unsigned int numid);
 struct snd_kcontrol *snd_ctl_find_id(struct snd_card * card, struct snd_ctl_elem_id *id);
 
diff --git a/sound/core/control.c b/sound/core/control.c
index 9ce00ed..db51e4e 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -466,6 +466,52 @@ error:
 }
 
 /**
+ * snd_ctl_activate_id - activate/inactivate the control of the given id
+ * @card: the card instance
+ * @id: the control id to activate/inactivate
+ * @active: non-zero to activate
+ *
+ * Finds the control instance with the given id, and activate or
+ * inactivate the control together with notification, if changed.
+ *
+ * Returns 0 if unchanged, 1 if changed, or a negative error code on failure.
+ */
+int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id,
+			int active)
+{
+	struct snd_kcontrol *kctl;
+	struct snd_kcontrol_volatile *vd;
+	unsigned int index_offset;
+	int ret;
+
+	down_write(&card->controls_rwsem);
+	kctl = snd_ctl_find_id(card, id);
+	if (kctl == NULL) {
+		ret = -ENOENT;
+		goto unlock;
+	}
+	index_offset = snd_ctl_get_ioff(kctl, &kctl->id);
+	vd = &kctl->vd[index_offset];
+	ret = 0;
+	if (active) {
+		if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE))
+			goto unlock;
+		vd->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+	} else {
+		if (vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE)
+			goto unlock;
+		vd->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
+	}
+	ret = 1;
+ unlock:
+	up_write(&card->controls_rwsem);
+	if (ret > 0)
+		snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, id);
+	return ret;
+}
+EXPORT_SYMBOL_GPL(snd_ctl_activate_id);
+
+/**
  * snd_ctl_rename_id - replace the id of a control on the card
  * @card: the card instance
  * @src_id: the old id
-- 
1.7.2.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: Add snd_ctl_activate_id()
  2011-03-09 20:03 [PATCH] ALSA: Add snd_ctl_activate_id() Mark Brown
@ 2011-03-10  6:52 ` Takashi Iwai
  2011-03-10 13:36   ` Mark Brown
  0 siblings, 1 reply; 3+ messages in thread
From: Takashi Iwai @ 2011-03-10  6:52 UTC (permalink / raw)
  To: Mark Brown; +Cc: alsa-devel

At Wed,  9 Mar 2011 20:03:41 +0000,
Mark Brown wrote:
> 
> From: Takashi Iwai <tiwai@suse.de>
> 
> Added a new API function snd_ctl_activate_id() for activate / inactivate
> the control element dynamically.
> 
> Signed-off-by: Takashi Iwai <tiwai@suse.de>
> Signed-off-by: Mark Brown <broonie@opensource.wolfsonmicro.com>
> ---
> 
> You wrote this patch a long time ago now - I'm currently working on a
> driver which I think can make use if it.  Is it OK if I cherry-pick it
> over into my code and push it through the ASoC branch if I do so?  Or
> if you could merge it in the coming merge window, but there's a risk I
> may come up with another way of doing things that doesn't need it.

I'm fine with pulling this from your tree.
This patch was written anyway per Liam's request :)


thanks,

Takashi

> 
>  include/sound/control.h |    2 ++
>  sound/core/control.c    |   46 ++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 48 insertions(+), 0 deletions(-)
> 
> diff --git a/include/sound/control.h b/include/sound/control.h
> index 7715e6f..e67db28 100644
> --- a/include/sound/control.h
> +++ b/include/sound/control.h
> @@ -115,6 +115,8 @@ int snd_ctl_add(struct snd_card * card, struct snd_kcontrol * kcontrol);
>  int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol);
>  int snd_ctl_remove_id(struct snd_card * card, struct snd_ctl_elem_id *id);
>  int snd_ctl_rename_id(struct snd_card * card, struct snd_ctl_elem_id *src_id, struct snd_ctl_elem_id *dst_id);
> +int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id,
> +			int active);
>  struct snd_kcontrol *snd_ctl_find_numid(struct snd_card * card, unsigned int numid);
>  struct snd_kcontrol *snd_ctl_find_id(struct snd_card * card, struct snd_ctl_elem_id *id);
>  
> diff --git a/sound/core/control.c b/sound/core/control.c
> index 9ce00ed..db51e4e 100644
> --- a/sound/core/control.c
> +++ b/sound/core/control.c
> @@ -466,6 +466,52 @@ error:
>  }
>  
>  /**
> + * snd_ctl_activate_id - activate/inactivate the control of the given id
> + * @card: the card instance
> + * @id: the control id to activate/inactivate
> + * @active: non-zero to activate
> + *
> + * Finds the control instance with the given id, and activate or
> + * inactivate the control together with notification, if changed.
> + *
> + * Returns 0 if unchanged, 1 if changed, or a negative error code on failure.
> + */
> +int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id,
> +			int active)
> +{
> +	struct snd_kcontrol *kctl;
> +	struct snd_kcontrol_volatile *vd;
> +	unsigned int index_offset;
> +	int ret;
> +
> +	down_write(&card->controls_rwsem);
> +	kctl = snd_ctl_find_id(card, id);
> +	if (kctl == NULL) {
> +		ret = -ENOENT;
> +		goto unlock;
> +	}
> +	index_offset = snd_ctl_get_ioff(kctl, &kctl->id);
> +	vd = &kctl->vd[index_offset];
> +	ret = 0;
> +	if (active) {
> +		if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE))
> +			goto unlock;
> +		vd->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
> +	} else {
> +		if (vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE)
> +			goto unlock;
> +		vd->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
> +	}
> +	ret = 1;
> + unlock:
> +	up_write(&card->controls_rwsem);
> +	if (ret > 0)
> +		snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, id);
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(snd_ctl_activate_id);
> +
> +/**
>   * snd_ctl_rename_id - replace the id of a control on the card
>   * @card: the card instance
>   * @src_id: the old id
> -- 
> 1.7.2.3
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] ALSA: Add snd_ctl_activate_id()
  2011-03-10  6:52 ` Takashi Iwai
@ 2011-03-10 13:36   ` Mark Brown
  0 siblings, 0 replies; 3+ messages in thread
From: Mark Brown @ 2011-03-10 13:36 UTC (permalink / raw)
  To: Takashi Iwai; +Cc: alsa-devel

On Thu, Mar 10, 2011 at 07:52:40AM +0100, Takashi Iwai wrote:

> I'm fine with pulling this from your tree.
> This patch was written anyway per Liam's request :)

I know, actually it was me who wanted it for a slightly different
purpose - I keep on getting stuck using it due to having to dig the
patch out of your unstable tree!.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2011-03-10 13:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-03-09 20:03 [PATCH] ALSA: Add snd_ctl_activate_id() Mark Brown
2011-03-10  6:52 ` Takashi Iwai
2011-03-10 13:36   ` Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).