Skip to content

Commit 1ad1825

Browse files
committed
alsactl: ucm: restore controls for other cards in group
When the primary card restores controls, all other cards in the card group should do this operation, too. Signed-off-by: Jaroslav Kysela <[email protected]>
1 parent f047a8a commit 1ad1825

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

alsactl/alsactl.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ int state_daemon(const char *file, const char *cardname, int period,
9898
int state_daemon_kill(const char *pidfile, const char *cmd);
9999
int clean(const char *cardname, char *const *extra_args);
100100
int snd_card_clean_cfgdir(const char *cfgdir, int cardno);
101+
void add_linked_card(int cardno);
101102

102103
/* export */
103104

alsactl/boot_params.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,8 @@ static void boot_params_update_restored(snd_config_t *card_compound, int skip_ca
893893
goto _next;
894894
}
895895

896+
add_linked_card(card_val);
897+
896898
_next:
897899
snd_ctl_close(handle);
898900
}

alsactl/state.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,33 @@
2929
#include <errno.h>
3030
#include "alsactl.h"
3131

32+
static int linked_cards[16];
33+
34+
static void init_linked_cards(void)
35+
{
36+
size_t index;
37+
38+
for (index = 0; index < ARRAY_SIZE(linked_cards); index++)
39+
linked_cards[index] = -1;
40+
}
41+
42+
void add_linked_card(int cardno)
43+
{
44+
size_t index;
45+
46+
for (index = 0; index < ARRAY_SIZE(linked_cards); index++) {
47+
if (linked_cards[index] == cardno)
48+
return;
49+
}
50+
51+
for (index = 0; index < ARRAY_SIZE(linked_cards); index++) {
52+
if (linked_cards[index] < 0) {
53+
linked_cards[index] = cardno;
54+
return;
55+
}
56+
}
57+
error("Too many linked cards!");
58+
}
3259

3360
static char *id_str(snd_ctl_elem_id_t *id)
3461
{
@@ -1703,10 +1730,11 @@ int load_state(const char *cfgdir, const char *file,
17031730
const char *initfile, int initflags,
17041731
const char *cardname, int do_init)
17051732
{
1706-
int err, finalerr = 0, open_failed, lock_fd;
1733+
int err, finalerr = 0, open_failed, lock_fd, cardno;
17071734
struct snd_card_iterator iter;
17081735
snd_config_t *config;
17091736
const char *cardname1;
1737+
size_t index;
17101738

17111739
config = NULL;
17121740
err = load_configuration(file, &config, &open_failed);
@@ -1723,6 +1751,7 @@ int load_state(const char *cfgdir, const char *file,
17231751
while ((cardname1 = snd_card_iterator_next(&iter)) != NULL) {
17241752
if (!do_init)
17251753
break;
1754+
init_linked_cards();
17261755
if (initflags & FLAG_UCM_WAIT)
17271756
wait_for_card(-1, iter.card);
17281757
lock_fd = card_lock(iter.card, LOCK_TIMEOUT);
@@ -1752,6 +1781,7 @@ int load_state(const char *cfgdir, const char *file,
17521781
if (err < 0)
17531782
goto out;
17541783
while ((cardname1 = snd_card_iterator_next(&iter)) != NULL) {
1784+
init_linked_cards();
17551785
if (initflags & FLAG_UCM_WAIT)
17561786
wait_for_card(-1, iter.card);
17571787
lock_fd = card_lock(iter.card, LOCK_TIMEOUT);
@@ -1780,6 +1810,17 @@ int load_state(const char *cfgdir, const char *file,
17801810
finalerr = err;
17811811
initfailed(iter.card, "restore", err);
17821812
}
1813+
/* for linked cards, restore controls, too */
1814+
for (index = 0; index < ARRAY_SIZE(linked_cards); index++) {
1815+
if ((cardno = linked_cards[index]) < 0)
1816+
break;
1817+
dbg("Restore for linked card %d", cardno);
1818+
if ((err = set_controls(cardno, config, 1))) {
1819+
if (!force_restore)
1820+
finalerr = err;
1821+
initfailed(cardno, "restore", err);
1822+
}
1823+
}
17831824
unlock_card:
17841825
card_unlock(lock_fd, iter.card);
17851826
}

0 commit comments

Comments
 (0)