From 1ad182507669008875860ecda8b00ac564bcbe6e Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Thu, 4 Dec 2025 15:06:39 +0100 Subject: [PATCH] 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 --- alsactl/alsactl.h | 1 + alsactl/boot_params.c | 2 ++ alsactl/state.c | 43 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/alsactl/alsactl.h b/alsactl/alsactl.h index 994485a..2aefb89 100644 --- a/alsactl/alsactl.h +++ b/alsactl/alsactl.h @@ -98,6 +98,7 @@ int state_daemon(const char *file, const char *cardname, int period, int state_daemon_kill(const char *pidfile, const char *cmd); int clean(const char *cardname, char *const *extra_args); int snd_card_clean_cfgdir(const char *cfgdir, int cardno); +void add_linked_card(int cardno); /* export */ diff --git a/alsactl/boot_params.c b/alsactl/boot_params.c index 736597e..f44526a 100644 --- a/alsactl/boot_params.c +++ b/alsactl/boot_params.c @@ -893,6 +893,8 @@ static void boot_params_update_restored(snd_config_t *card_compound, int skip_ca goto _next; } + add_linked_card(card_val); + _next: snd_ctl_close(handle); } diff --git a/alsactl/state.c b/alsactl/state.c index c6a1630..2942f3f 100644 --- a/alsactl/state.c +++ b/alsactl/state.c @@ -29,6 +29,33 @@ #include #include "alsactl.h" +static int linked_cards[16]; + +static void init_linked_cards(void) +{ + size_t index; + + for (index = 0; index < ARRAY_SIZE(linked_cards); index++) + linked_cards[index] = -1; +} + +void add_linked_card(int cardno) +{ + size_t index; + + for (index = 0; index < ARRAY_SIZE(linked_cards); index++) { + if (linked_cards[index] == cardno) + return; + } + + for (index = 0; index < ARRAY_SIZE(linked_cards); index++) { + if (linked_cards[index] < 0) { + linked_cards[index] = cardno; + return; + } + } + error("Too many linked cards!"); +} static char *id_str(snd_ctl_elem_id_t *id) { @@ -1703,10 +1730,11 @@ int load_state(const char *cfgdir, const char *file, const char *initfile, int initflags, const char *cardname, int do_init) { - int err, finalerr = 0, open_failed, lock_fd; + int err, finalerr = 0, open_failed, lock_fd, cardno; struct snd_card_iterator iter; snd_config_t *config; const char *cardname1; + size_t index; config = NULL; err = load_configuration(file, &config, &open_failed); @@ -1723,6 +1751,7 @@ int load_state(const char *cfgdir, const char *file, while ((cardname1 = snd_card_iterator_next(&iter)) != NULL) { if (!do_init) break; + init_linked_cards(); if (initflags & FLAG_UCM_WAIT) wait_for_card(-1, iter.card); lock_fd = card_lock(iter.card, LOCK_TIMEOUT); @@ -1752,6 +1781,7 @@ int load_state(const char *cfgdir, const char *file, if (err < 0) goto out; while ((cardname1 = snd_card_iterator_next(&iter)) != NULL) { + init_linked_cards(); if (initflags & FLAG_UCM_WAIT) wait_for_card(-1, iter.card); lock_fd = card_lock(iter.card, LOCK_TIMEOUT); @@ -1780,6 +1810,17 @@ int load_state(const char *cfgdir, const char *file, finalerr = err; initfailed(iter.card, "restore", err); } + /* for linked cards, restore controls, too */ + for (index = 0; index < ARRAY_SIZE(linked_cards); index++) { + if ((cardno = linked_cards[index]) < 0) + break; + dbg("Restore for linked card %d", cardno); + if ((err = set_controls(cardno, config, 1))) { + if (!force_restore) + finalerr = err; + initfailed(cardno, "restore", err); + } + } unlock_card: card_unlock(lock_fd, iter.card); } -- 2.47.3