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
3360static 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+ }
17831824unlock_card :
17841825 card_unlock (lock_fd , iter .card );
17851826 }
0 commit comments