1 /*
2 * Copyright (c) 2019-2025 Allwinner Technology Co., Ltd. ALL rights reserved.
3 *
4 * Allwinner is a trademark of Allwinner Technology Co.,Ltd., registered in
5 * the the people's Republic of China and other countries.
6 * All Allwinner Technology Co.,Ltd. trademarks are used with permission.
7 *
8 * DISCLAIMER
9 * THIRD PARTY LICENCES MAY BE REQUIRED TO IMPLEMENT THE SOLUTION/PRODUCT.
10 * IF YOU NEED TO INTEGRATE THIRD PARTY’S TECHNOLOGY (SONY, DTS, DOLBY, AVS OR MPEGLA, ETC.)
11 * IN ALLWINNERS’SDK OR PRODUCTS, YOU SHALL BE SOLELY RESPONSIBLE TO OBTAIN
12 * ALL APPROPRIATELY REQUIRED THIRD PARTY LICENCES.
13 * ALLWINNER SHALL HAVE NO WARRANTY, INDEMNITY OR OTHER OBLIGATIONS WITH RESPECT TO MATTERS
14 * COVERED UNDER ANY REQUIRED THIRD PARTY LICENSE.
15 * YOU ARE SOLELY RESPONSIBLE FOR YOUR USAGE OF THIRD PARTY’S TECHNOLOGY.
16 *
17 *
18 * THIS SOFTWARE IS PROVIDED BY ALLWINNER"AS IS" AND TO THE MAXIMUM EXTENT
19 * PERMITTED BY LAW, ALLWINNER EXPRESSLY DISCLAIMS ALL WARRANTIES OF ANY KIND,
20 * WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING WITHOUT LIMITATION REGARDING
21 * THE TITLE, NON-INFRINGEMENT, ACCURACY, CONDITION, COMPLETENESS, PERFORMANCE
22 * OR MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
23 * IN NO EVENT SHALL ALLWINNER BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26 * LOSS OF USE, DATA, OR PROFITS, OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
28 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
30 * OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32 #include <stdio.h>
33 #include <string.h>
34 #include <aw-alsa-lib/pcm.h>
35 #include <aw-alsa-lib/control.h>
36 #include <aw-alsa-lib/pcm_plugin.h>
37 #include "pcm_local.h"
38 
snd_ctl_open(const char ** name)39 void snd_ctl_open(const char **name)
40 {
41     const snd_pcm_config_t *pcm_config = NULL;
42     char ctl_name[32] = "ctl.!";
43 
44     strcat(ctl_name, *name);
45     pcm_config = snd_pcm_config_get_config(ctl_name);
46     if (!pcm_config)
47         return ;
48     struct {
49         const char *type;
50         const char *name;
51     } snd_pcm_open_ctl_name_table[] = {
52         { "hw", ((const snd_pcm_hw_config_t *)(pcm_config->config))->card_name},
53     };
54 
55     int size = sizeof(snd_pcm_open_ctl_name_table) / sizeof(snd_pcm_open_ctl_name_table[0]);
56     int i;
57     for (i = 0; i < size; ++i) {
58         if (0 == strcmp(pcm_config->type, snd_pcm_open_ctl_name_table[i].type)) {
59             *name = snd_pcm_open_ctl_name_table[i].name;
60             break;
61         }
62     }
63 }
64 
snd_ctl_num(const char * name)65 int snd_ctl_num(const char *name)
66 {
67     snd_ctl_open(&name);
68 
69     return ksnd_ctl_num(name);
70 }
71 
snd_ctl_get_bynum(const char * name,const unsigned int elem_num,snd_ctl_info_t * info)72 int snd_ctl_get_bynum(const char *name, const unsigned int elem_num, snd_ctl_info_t *info)
73 {
74     int ret;
75 
76     snd_ctl_open(&name);
77     memset(info, 0, sizeof(snd_ctl_info_t));
78     ret = ksnd_ctl_get_bynum(name, elem_num, info);
79 
80     return ret;
81 }
82 
snd_ctl_get(const char * name,const char * elem,snd_ctl_info_t * info)83 int snd_ctl_get(const char *name, const char *elem, snd_ctl_info_t *info)
84 {
85     int ret;
86 
87     memset(info, 0, sizeof(snd_ctl_info_t));
88     ret = ksnd_ctl_get(name, elem, info);
89     awalsa_debug("ret=%d\n", ret);
90     return ret;
91 }
92 
snd_ctl_set_bynum(const char * name,const unsigned int elem_num,unsigned int val)93 int snd_ctl_set_bynum(const char *name, const unsigned int elem_num, unsigned int val)
94 {
95     int ret;
96 
97     ret = ksnd_ctl_set_bynum(name, elem_num, val);
98     return ret;
99 }
100 
snd_ctl_set(const char * name,const char * elem,unsigned int val)101 int snd_ctl_set(const char *name, const char *elem, unsigned int val)
102 {
103     int ret;
104 
105     ret = ksnd_ctl_set(name, elem, val);
106     return ret;
107 }
108 
snd_ctl_add(const char * name,snd_ctl_info_t * info)109 int snd_ctl_add(const char *name, snd_ctl_info_t *info)
110 {
111     int ret;
112 
113     ret = ksnd_ctl_add_elem(name, (void *)info);
114     return ret;
115 }
116 
snd_ctl_remove(const char * name,const unsigned int elem_num)117 int snd_ctl_remove(const char *name, const unsigned int elem_num)
118 {
119     int ret;
120     ret = ksnd_ctl_remove_elem(name, elem_num);
121     return ret;
122 }
123