ALSA: Add snd_ctl_activate_id()

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>

authored by Takashi Iwai and committed by Mark Brown 3cbdd753 80e1b84f

+48
+2
include/sound/control.h
··· 115 115 int snd_ctl_remove(struct snd_card * card, struct snd_kcontrol * kcontrol); 116 116 int snd_ctl_remove_id(struct snd_card * card, struct snd_ctl_elem_id *id); 117 117 int snd_ctl_rename_id(struct snd_card * card, struct snd_ctl_elem_id *src_id, struct snd_ctl_elem_id *dst_id); 118 + int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id, 119 + int active); 118 120 struct snd_kcontrol *snd_ctl_find_numid(struct snd_card * card, unsigned int numid); 119 121 struct snd_kcontrol *snd_ctl_find_id(struct snd_card * card, struct snd_ctl_elem_id *id); 120 122
+46
sound/core/control.c
··· 466 466 } 467 467 468 468 /** 469 + * snd_ctl_activate_id - activate/inactivate the control of the given id 470 + * @card: the card instance 471 + * @id: the control id to activate/inactivate 472 + * @active: non-zero to activate 473 + * 474 + * Finds the control instance with the given id, and activate or 475 + * inactivate the control together with notification, if changed. 476 + * 477 + * Returns 0 if unchanged, 1 if changed, or a negative error code on failure. 478 + */ 479 + int snd_ctl_activate_id(struct snd_card *card, struct snd_ctl_elem_id *id, 480 + int active) 481 + { 482 + struct snd_kcontrol *kctl; 483 + struct snd_kcontrol_volatile *vd; 484 + unsigned int index_offset; 485 + int ret; 486 + 487 + down_write(&card->controls_rwsem); 488 + kctl = snd_ctl_find_id(card, id); 489 + if (kctl == NULL) { 490 + ret = -ENOENT; 491 + goto unlock; 492 + } 493 + index_offset = snd_ctl_get_ioff(kctl, &kctl->id); 494 + vd = &kctl->vd[index_offset]; 495 + ret = 0; 496 + if (active) { 497 + if (!(vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE)) 498 + goto unlock; 499 + vd->access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; 500 + } else { 501 + if (vd->access & SNDRV_CTL_ELEM_ACCESS_INACTIVE) 502 + goto unlock; 503 + vd->access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; 504 + } 505 + ret = 1; 506 + unlock: 507 + up_write(&card->controls_rwsem); 508 + if (ret > 0) 509 + snd_ctl_notify(card, SNDRV_CTL_EVENT_MASK_INFO, id); 510 + return ret; 511 + } 512 + EXPORT_SYMBOL_GPL(snd_ctl_activate_id); 513 + 514 + /** 469 515 * snd_ctl_rename_id - replace the id of a control on the card 470 516 * @card: the card instance 471 517 * @src_id: the old id