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