msm8960_use_cases.h revision 396ebb32c3a800e5c9a972af3fcec55e351996e3
1/*
2 * Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *   * Redistributions of source code must retain the above copyright
8 *     notice, this list of conditions and the following disclaimer.
9 *   * Redistributions in binary form must reproduce the above
10 *     copyright notice, this list of conditions and the following
11 *     disclaimer in the documentation and/or other materials provided
12 *     with the distribution.
13 *   * Neither the name of Code Aurora Forum, Inc. nor the names of its
14 *     contributors may be used to endorse or promote products derived
15 *     from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29#ifndef _MSM8960_USE_CASES_H_
30#define _MSM8960_USE_CASES_H_
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#include "alsa_ucm.h"
37#include "alsa_audio.h"
38#include <stdbool.h>
39#include <pthread.h>
40#define SND_UCM_END_OF_LIST "end"
41
42/* ACDB Device ID macros */
43#define CAP_RX 0x1
44#define CAP_TX 0x2
45#define CAP_VOICE 0x4
46#define DEVICE_HANDSET_RX_ACDB_ID                       7 // HANDSET_SPKR
47#define DEVICE_HANDSET_RX_TMUS_ACDB_ID                  81// HANDSET_SPKR
48#define DEVICE_HANDSET_TX_ACDB_ID                       4 // HANDSET_MIC
49#define DEVICE_SPEAKER_MONO_RX_ACDB_ID                  14// SPKR_PHONE_SPKR_MONO
50#define DEVICE_SPEAKER_STEREO_RX_ACDB_ID                15// SPKR_PHONE_SPKR_STEREO
51#define DEVICE_SPEAKER_TX_ACDB_ID                       11// SPKR_PHONE_MIC
52#define DEVICE_HEADSET_RX_ACDB_ID                       10// HEADSET_SPKR_STEREO
53#define DEVICE_HEADSET_TX_ACDB_ID                       8 // HEADSET_MIC
54#define DEVICE_DUALMIC_HANDSET_TX_BROADSIDE_ACDB_ID     5 // HANDSET_MIC_BROADSIDE
55#define DEVICE_DUALMIC_HANDSET_TX_ENDFIRE_ACDB_ID       6 // HANDSET_MIC_ENDFIRE
56#define DEVICE_DUALMIC_HANDSET_TX_ENDFIRE_TMUS_ACDB_ID  91// HANDSET_MIC_ENDFIRE
57#define DEVICE_DUALMIC_SPEAKER_TX_BROADSIDE_ACDB_ID     12// SPKR_PHONE_MIC_BROADSIDE
58#define DEVICE_DUALMIC_SPEAKER_TX_ENDFIRE_ACDB_ID       13// SPKR_PHONE_MIC_ENDFIRE
59#define DEVICE_TTY_HEADSET_MONO_RX_ACDB_ID              17// TTY_HEADSET_SPKR
60#define DEVICE_TTY_HEADSET_MONO_TX_ACDB_ID              16// TTY_HEADSET_MIC
61#define DEVICE_BT_SCO_RX_ACDB_ID                        22// BT_SCO_SPKR
62#define DEVICE_BT_SCO_TX_ACDB_ID                        21// BT_SCO_SPKR
63#define DEVICE_BT_SCO_RX_WB_ACDB_ID                     39// BT_SCO_WB_SPKR
64#define DEVICE_BT_SCO_TX_WB_ACDB_ID                     38// BT_SCO_WB_MIC
65#define DEVICE_SPEAKER_HEADSET_RX_ACDB_ID               DEVICE_HEADSET_RX_ACDB_ID // Use headset calibration
66#define DEVICE_HDMI_STEREO_RX_ACDB_ID                   18// HDMI_SPKR
67#define DEVICE_ANC_HEADSET_STEREO_RX_ACDB_ID            26// ANC RX, same as regular headset
68#define DEVICE_QUADMIC_ACDB_ID                          19// QUADMIC_SKPR
69#define DEVICE_PROXY_RX_ACDB_ID                         DEVICE_HDMI_STEREO_RX_ACDB_ID
70#define DEVICE_TTY_VCO_HANDSET_TX_ACDB_ID               36// TTY_VCO_HANDSET_MIC
71#define DEVICE_TTY_HCO_HANDSET_RX_ACDB_ID               37// TTY_HCO_HANDSET_SPRK
72#define DEVICE_HANDSET_TX_FV5_ACDB_ID                   50
73#define DEVICE_DUALMIC_HANDSET_TX_ENDFIRE_FV5_ACDB_ID   51
74#define DEVICE_SPEAKER_TX_FV5_ACDB_ID                   52
75#define DEVICE_DUALMIC_SPEAKER_TX_ENDFIRE_FV5_ACDB_ID   53
76#define DEVICE_INCALL_VOICE_RECORD_STEREO_ACDB_ID       45
77#define DEVICE_INCALL_MUSIC_DELIVERY_MONO_ACDB_ID       46
78#define DEVICE_INCALL_VOICE_RECORD_MONO_ACDB_ID         47
79#define DEVICE_CAMCORDER_TX_ACDB_ID                     61// CAMCORDER_TX
80#define DEVICE_VOICE_RECOGNITION_ACDB_ID                62// VOICE_RECOGNITION
81
82/* mixer control type */
83#define TYPE_INT            0
84#define TYPE_STR            1
85#define TYPE_MULTI_VAL      2
86
87/* Maximum string length of use case and device combination */
88#define MAX_UC_LEN 100
89/* Maximum string length of use case or device */
90#define MAX_STR_LEN 50
91
92/* Returns maximum length of strings x and y */
93#define MAX_LEN(x,y) ((strlen(x)>strlen(y))?strlen(x):strlen(y))
94
95/* Mixer control list type enum*/
96enum {
97    CTRL_LIST_VERB,
98    CTRL_LIST_DEVICE,
99    CTRL_LIST_MODIFIER,
100};
101
102/* mixer control structure */
103typedef struct mixer_control {
104    char *control_name;
105    unsigned type;
106    unsigned value;
107    char *string;
108    char **mulval;
109}mixer_control_t;
110
111/* Use case mixer controls structure */
112typedef struct card_mctrl {
113    char *case_name;
114    int ena_mixer_count;
115    mixer_control_t *ena_mixer_list;
116    int dis_mixer_count;
117    mixer_control_t *dis_mixer_list;
118    char *playback_dev_name;
119    char *capture_dev_name;
120    int acdb_id;
121    int capability;
122    char *effects_mixer_ctl;
123}card_mctrl_t;
124
125/* identifier node structure for identifier list*/
126struct snd_ucm_ident_node {
127    int active;
128    int capability;
129    char ident[MAX_STR_LEN];
130    struct snd_ucm_ident_node *next;
131};
132
133/* Structure to maintain the valid devices and
134 * modifiers list per each use case */
135typedef struct use_case_verb {
136    char *use_case_name;
137    char **device_list;
138    char **modifier_list;
139    int verb_count;
140    int device_count;
141    int mod_count;
142    card_mctrl_t *verb_ctrls;
143    card_mctrl_t *device_ctrls;
144    card_mctrl_t *mod_ctrls;
145}use_case_verb_t;
146
147/* SND card context structure */
148typedef struct card_ctxt {
149    char *card_name;
150    int card_number;
151    char *control_device;
152    struct mixer *mixer_handle;
153    char current_verb[MAX_STR_LEN];
154    struct snd_ucm_ident_node *dev_list_head;
155    struct snd_ucm_ident_node *mod_list_head;
156    pthread_mutex_t card_lock;
157    pthread_mutexattr_t card_lock_attr;
158    int current_verb_index;
159    use_case_verb_t *use_case_verb_list;
160    char **verb_list;
161}card_ctxt_t;
162
163/** use case manager structure */
164struct snd_use_case_mgr {
165    int snd_card_index;
166    int device_list_count;
167    int modifier_list_count;
168    char **current_device_list;
169    char **current_modifier_list;
170    int current_tx_device;
171    int current_rx_device;
172    card_ctxt_t *card_ctxt_ptr;
173    pthread_t thr;
174    void *acdb_handle;
175    bool isFusion3Platform;
176};
177
178#define MAX_NUM_CARDS (sizeof(card_list)/sizeof(char *))
179
180/* Valid sound cards list */
181static const char *card_list[] = {
182    "snd_soc_msm",
183    "snd_soc_msm_2x",
184    "snd_soc_msm_2x_Fusion3",
185    "snd_soc_msm_Sitar",
186};
187
188typedef struct card_mapping {
189    char card_name[50];
190    int card_number;
191}card_mapping_t;
192
193/* sound card name and number mapping */
194static card_mapping_t card_mapping_list[] = {
195    {"snd_soc_msm", 0},
196    {"snd_soc_msm_2x", 0},
197    {"snd_soc_msm_2x_Fusion3", 0},
198    {"snd_soc_msm_Sitar", 0},
199};
200
201/* New use cases, devices and modifiers added
202 * which are not part of existing macros
203 */
204#define SND_USE_CASE_VERB_FM_REC         "FM REC"
205#define SND_USE_CASE_VERB_FM_A2DP_REC   "FM A2DP REC"
206#define SND_USE_CASE_VERB_HIFI_REC       "HiFi Rec"
207#define SND_USE_CASE_VERB_HIFI_LOWLATENCY_REC       "HiFi Lowlatency Rec"
208#define SND_USE_CASE_VERB_DL_REC	 "DL REC"
209#define SND_USE_CASE_VERB_UL_DL_REC      "UL DL REC"
210#define SND_USE_CASE_VERB_HIFI_TUNNEL    "HiFi Tunnel"
211#define SND_USE_CASE_VERB_HIFI_LOWLATENCY_MUSIC    "HiFi Lowlatency"
212#define SND_USE_CASE_VERB_HIFI2       "HiFi2"
213#define SND_USE_CASE_VERB_INCALL_REC   "Incall REC"
214#define SND_USE_CASE_VERB_MI2S        "MI2S"
215#define SND_USE_CASE_VERB_VOLTE    "VoLTE"
216#define SND_USE_CASE_VERB_ADSP_TESTFWK "ADSP testfwk"
217
218#define SND_USE_CASE_DEV_FM_TX           "FM Tx"
219#define SND_USE_CASE_DEV_ANC_HEADSET     "ANC Headset"
220#define SND_USE_CASE_DEV_BTSCO_NB_RX        "BT SCO Rx"
221#define SND_USE_CASE_DEV_BTSCO_NB_TX        "BT SCO Tx"
222#define SND_USE_CASE_DEV_BTSCO_WB_RX        "BT SCO WB Rx"
223#define SND_USE_CASE_DEV_BTSCO_WB_TX        "BT SCO WB Tx"
224#define SND_USE_CASE_DEV_SPEAKER_HEADSET "Speaker Headset"
225#define SND_USE_CASE_DEV_SPEAKER_ANC_HEADSET "Speaker ANC Headset"
226#define SND_USE_CASE_DEV_SPEAKER_FM_TX   "Speaker FM Tx"
227#define SND_USE_CASE_DEV_TTY_HEADSET_RX  "TTY Headset Rx"
228#define SND_USE_CASE_DEV_TTY_HEADSET_TX  "TTY Headset Tx"
229#define SND_USE_CASE_DEV_TTY_FULL_RX  "TTY Full Rx"
230#define SND_USE_CASE_DEV_TTY_FULL_TX  "TTY Full Tx"
231#define SND_USE_CASE_DEV_TTY_HANDSET_RX  "TTY Handset Rx"
232#define SND_USE_CASE_DEV_TTY_HANDSET_TX  "TTY Handset Tx"
233#define SND_USE_CASE_DEV_TTY_HANDSET_ANALOG_TX  "TTY Handset Analog Tx"
234#define SND_USE_CASE_DEV_DUAL_MIC_BROADSIDE "DMIC Broadside"
235#define SND_USE_CASE_DEV_DUAL_MIC_BROADSIDE_VREC "DMIC Broadside Voice Rec"
236#define SND_USE_CASE_DEV_DUAL_MIC_ENDFIRE "DMIC Endfire"
237#define SND_USE_CASE_DEV_DUAL_MIC_ENDFIRE_TMUS "DMIC Endfire TMUS"
238#define SND_USE_CASE_DEV_DUAL_MIC_ENDFIRE_VREC "DMIC Endfire Voice Rec"
239#define SND_USE_CASE_DEV_SPEAKER_DUAL_MIC_BROADSIDE "Speaker DMIC Broadside"
240#define SND_USE_CASE_DEV_SPEAKER_DUAL_MIC_ENDFIRE "Speaker DMIC Endfire"
241#define SND_USE_CASE_DEV_HDMI_TX             "HDMI Tx"
242#define SND_USE_CASE_DEV_HDMI_SPDIF          "HDMI SPDIF"
243#define SND_USE_CASE_DEV_QUAD_MIC "QMIC"
244#define SND_USE_CASE_DEV_SSR_QUAD_MIC "SSR QMIC"
245#define SND_USE_CASE_DEV_PROXY_RX     "PROXY Rx"
246#define SND_USE_CASE_DEV_PROXY_TX     "PROXY Tx"
247#define SND_USE_CASE_DEV_HDMI_SPEAKER     "HDMI Speaker"
248#define SND_USE_CASE_DEV_SPDIF_SPEAKER     "SPDIF Speaker"
249#define SND_USE_CASE_DEV_SPDIF_HANDSET     "SPDIF Earpiece"
250#define SND_USE_CASE_DEV_SPDIF_HEADSET     "SPDIF Headphones"
251#define SND_USE_CASE_DEV_SPDIF_ANC_HEADSET     "SPDIF ANC Headset"
252#define SND_USE_CASE_DEV_SPDIF_SPEAKER_HEADSET "SPDIF Speaker Headset"
253#define SND_USE_CASE_DEV_SPDIF_SPEAKER_ANC_HEADSET "SPDIF Speaker ANC Headset"
254#define SND_USE_CASE_DEV_DUMMY_TX "Dummy Tx"
255#define SND_USE_CASE_DEV_PROXY_RX_SPEAKER     "PROXY Rx Speaker"
256#define SND_USE_CASE_DEV_PROXY_RX_HANDSET     "PROXY Rx Earpiece"
257#define SND_USE_CASE_DEV_PROXY_RX_HEADSET     "PROXY Rx Headphones"
258#define SND_USE_CASE_DEV_PROXY_RX_ANC_HEADSET     "PROXY Rx ANC Headset"
259#define SND_USE_CASE_DEV_PROXY_RX_SPEAKER_HEADSET "PROXY Rx Speaker Headset"
260#define SND_USE_CASE_DEV_PROXY_RX_SPEAKER_ANC_HEADSET "PROXY Rx Speaker ANC Headset"
261#define SND_USE_CASE_DEV_CAMCORDER_TX       "Camcorder Tx"
262#define SND_USE_CASE_DEV_VOICE_RECOGNITION  "Voice Recognition"
263#define SND_USE_CASE_DEV_VOC_EARPIECE       "Voice Earpiece"
264#define SND_USE_CASE_DEV_VOC_EARPIECE_TMUS  "Voice Earpiece TMUS"
265#define SND_USE_CASE_DEV_VOC_HEADPHONE      "Voice Headphones"
266#define SND_USE_CASE_DEV_VOC_HEADSET        "Voice Headset"
267#define SND_USE_CASE_DEV_VOC_ANC_HEADSET    "Voice ANC Headset"
268#define SND_USE_CASE_DEV_VOC_SPEAKER        "Voice Speaker"
269#define SND_USE_CASE_DEV_VOC_LINE           "Voice Line"
270
271#define SND_USE_CASE_MOD_PLAY_FM         "Play FM"
272#define SND_USE_CASE_MOD_CAPTURE_FM      "Capture FM"
273#define SND_USE_CASE_MOD_CAPTURE_LOWLATENCY_MUSIC     "Capture Lowlatency Music"
274#define SND_USE_CASE_MOD_CAPTURE_A2DP_FM "Capture A2DP FM"
275#define SND_USE_CASE_MOD_PLAY_LPA        "Play LPA"
276#define SND_USE_CASE_MOD_PLAY_VOIP       "Play VOIP"
277#define SND_USE_CASE_MOD_CAPTURE_VOIP    "Capture VOIP"
278#define SND_USE_CASE_MOD_CAPTURE_VOICE_DL       "Capture Voice Downlink"
279#define SND_USE_CASE_MOD_CAPTURE_VOICE_UL_DL    "Capture Voice Uplink Downlink"
280#define SND_USE_CASE_MOD_PLAY_TUNNEL     "Play Tunnel"
281#define SND_USE_CASE_MOD_PLAY_LOWLATENCY_MUSIC     "Play Lowlatency Music"
282#define SND_USE_CASE_MOD_PLAY_MUSIC2       "Play Music2"
283#define SND_USE_CASE_MOD_PLAY_MI2S       "Play MI2S"
284#define SND_USE_CASE_MOD_PLAY_VOLTE   "Play VoLTE"
285
286/* List utility functions for maintaining enabled devices and modifiers */
287static int snd_ucm_add_ident_to_list(struct snd_ucm_ident_node **head, const char *value);
288static char *snd_ucm_get_value_at_index(struct snd_ucm_ident_node *head, int index);
289static int snd_ucm_get_size_of_list(struct snd_ucm_ident_node *head);
290static int snd_ucm_del_ident_from_list(struct snd_ucm_ident_node **head, const char *value);
291static int snd_ucm_free_list(struct snd_ucm_ident_node **head);
292static void snd_ucm_print_list(struct snd_ucm_ident_node *head);
293static void snd_ucm_set_status_at_index(struct snd_ucm_ident_node *head, const char *ident, int status, int capability);
294static int snd_ucm_get_status_at_index(struct snd_ucm_ident_node *head, const char *ident);
295struct snd_ucm_ident_node *snd_ucm_get_device_node(struct snd_ucm_ident_node *head, int index);
296static int snd_ucm_parse_verb(snd_use_case_mgr_t **uc_mgr, const char *file_name, int index);
297static int get_verb_count(const char *nxt_str);
298int snd_use_case_mgr_wait_for_parsing(snd_use_case_mgr_t *uc_mgr);
299int snd_use_case_set_case(snd_use_case_mgr_t *uc_mgr, const char *identifier,
300                          const char *value, const char *usecase);
301static int get_usecase_type(snd_use_case_mgr_t *uc_mgr, const char *usecase);
302static int parse_single_config_format(snd_use_case_mgr_t **uc_mgr, char *current_str, int num_verbs);
303static int get_num_verbs_config_format(const char *nxt_str);
304static int get_num_device_config_format(const char *nxt_str);
305static int get_num_mod_config_format(const char *nxt_str);
306static int is_single_config_format(const char *nxt_str);
307/* Parse functions */
308static int snd_ucm_parse(snd_use_case_mgr_t **uc_mgr);
309static int snd_ucm_parse_section(snd_use_case_mgr_t **uc_mgr, char **cur_str, char **nxt_str, int verb_index, int ctrl_list_type);
310static int snd_ucm_extract_name(char *buf, char **case_name);
311static int snd_ucm_extract_acdb(char *buf, int *id, int *cap);
312static int snd_ucm_extract_effects_mixer_ctl(char *buf, char **mixer_name);
313static int snd_ucm_extract_dev_name(char *buf, char **dev_name);
314static int snd_ucm_extract_controls(char *buf, mixer_control_t **mixer_list, int count);
315static int snd_ucm_print(snd_use_case_mgr_t *uc_mgr);
316static void snd_ucm_free_mixer_list(snd_use_case_mgr_t **uc_mgr);
317#ifdef __cplusplus
318}
319#endif
320
321#endif
322