1 /*
2  *  Advanced Linux Sound Architecture Control Program - UCM Initialization
3  *  Copyright (c) by Jaroslav Kysela <perex@perex.cz>
4  *
5  *
6  *   This program is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU General Public License as published by
8  *   the Free Software Foundation; either version 2 of the License, or
9  *   (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU General Public License for more details.
15  *
16  *   You should have received a copy of the GNU General Public License
17  *   along with this program; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 
22 #include "aconfig.h"
23 #include <stddef.h>
24 #include "alsactl.h"
25 
26 #ifdef HAVE_ALSA_USE_CASE_H
27 
28 #include <alsa/use-case.h>
29 
30 /*
31  * Keep it as simple as possible. Execute commands from the
32  * FixedBootSequence and BootSequence only.
33  */
init_ucm(int flags, int cardno)34 int init_ucm(int flags, int cardno)
35 {
36 	snd_use_case_mgr_t *uc_mgr;
37 	char id[32], *nodev;
38 	int err;
39 
40 	if (flags & FLAG_UCM_DISABLED) {
41 		dbg("ucm disabled");
42 		return -ENXIO;
43 	}
44 
45 	nodev = (flags & FLAG_UCM_NODEV) ? "" : "-";
46 	snprintf(id, sizeof(id), "%shw:%d", nodev, cardno);
47 	err = snd_use_case_mgr_open(&uc_mgr, id);
48 	dbg("ucm open '%s': %d", id, err);
49 	if (err < 0)
50 		return err;
51 	if (flags & FLAG_UCM_FBOOT) {
52 		err = snd_use_case_set(uc_mgr, "_fboot", NULL);
53 		dbg("ucm _fboot: %d", err);
54 		if (err == -ENOENT && (flags & FLAG_UCM_BOOT) != 0) {
55 			/* nothing */
56 		} else if (err < 0) {
57 			goto _error;
58 		}
59 	}
60 	if (flags & FLAG_UCM_BOOT) {
61 		err = snd_use_case_set(uc_mgr, "_boot", NULL);
62 		dbg("ucm _boot: %d", err);
63 		if (err < 0)
64 			goto _error;
65 		if ((flags & FLAG_UCM_DEFAULTS) != 0)
66 			err = snd_use_case_set(uc_mgr, "_defaults", NULL);
67 	}
68 _error:
69 	snd_use_case_mgr_close(uc_mgr);
70 	return err;
71 }
72 
73 #else
74 
init_ucm(int flags, int cardno)75 int init_ucm(int flags, int cardno)
76 {
77 	return -ENXIO;
78 }
79 
80 #endif
81