blob: 9b397b44bad6bbf1a757428670b05ddf51a1aff9 [file] [log] [blame]
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08001/*
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -07002 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
3 * Not a contribution.
4 *
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -08005 * Copyright (C) 2013 The Android Open Source Project
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 */
19
Eric Laurentb23d5282013-05-14 15:27:20 -070020#ifndef QCOM_AUDIO_HW_H
21#define QCOM_AUDIO_HW_H
22
23#include <cutils/list.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080024#include <hardware/audio.h>
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080025#include <tinyalsa/asoundlib.h>
26
27#include <audio_route/audio_route.h>
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070028#include "voice.h"
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080029
Eric Laurentb23d5282013-05-14 15:27:20 -070030/* Flags used to initialize acdb_settings variable that goes to ACDB library */
31#define DMIC_FLAG 0x00000002
Mingming Yin8e5a4f62013-10-07 15:23:41 -070032#define QMIC_FLAG 0x00000004
Eric Laurentb23d5282013-05-14 15:27:20 -070033#define TTY_MODE_OFF 0x00000010
34#define TTY_MODE_FULL 0x00000020
35#define TTY_MODE_VCO 0x00000040
36#define TTY_MODE_HCO 0x00000080
37#define TTY_MODE_CLEAR 0xFFFFFF0F
38
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080039#define ACDB_DEV_TYPE_OUT 1
40#define ACDB_DEV_TYPE_IN 2
41
Eric Laurentb23d5282013-05-14 15:27:20 -070042#define MAX_SUPPORTED_CHANNEL_MASKS 2
Ravi Kumar Alamanda72c411f2013-02-12 02:09:33 -080043
Eric Laurentb23d5282013-05-14 15:27:20 -070044typedef int snd_device_t;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080045
46/* These are the supported use cases by the hardware.
47 * Each usecase is mapped to a specific PCM device.
48 * Refer to pcm_device_table[].
49 */
50typedef enum {
51 USECASE_INVALID = -1,
52 /* Playback usecases */
53 USECASE_AUDIO_PLAYBACK_DEEP_BUFFER = 0,
54 USECASE_AUDIO_PLAYBACK_LOW_LATENCY,
55 USECASE_AUDIO_PLAYBACK_MULTI_CH,
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -070056 /* FM usecase */
57 USECASE_AUDIO_PLAYBACK_FM,
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080058
59 /* Capture usecases */
60 USECASE_AUDIO_RECORD,
61 USECASE_AUDIO_RECORD_LOW_LATENCY,
62
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070063 /* Voice usecase */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080064 USECASE_VOICE_CALL,
65
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -070066 /* Voice extension usecases */
67 USECASE_VOICE2_CALL,
68 USECASE_VOLTE_CALL,
69 USECASE_QCHAT_CALL,
70
Shiv Maliyappanahallida107642013-10-17 11:16:13 -070071 USECASE_INCALL_REC_UPLINK,
72 USECASE_INCALL_REC_DOWNLINK,
73 USECASE_INCALL_REC_UPLINK_AND_DOWNLINK,
74
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080075 AUDIO_USECASE_MAX
76} audio_usecase_t;
77
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080078#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
79
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080080/*
81 * tinyAlsa library interprets period size as number of frames
82 * one frame = channel_count * sizeof (pcm sample)
83 * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes
84 * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes
85 * We should take care of returning proper size when AudioFlinger queries for
86 * the buffer size of an input/output stream
87 */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080088
89struct stream_out {
90 struct audio_stream_out stream;
Eric Laurent150dbfe2013-02-27 14:31:02 -080091 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080092 struct pcm_config config;
93 struct pcm *pcm;
94 int standby;
95 int pcm_device_id;
96 audio_channel_mask_t channel_mask;
97 audio_devices_t devices;
98 audio_output_flags_t flags;
99 audio_usecase_t usecase;
100 /* Array of supported channel mask configurations. +1 so that the last entry is always 0 */
101 audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1];
Eric Laurenta9024de2013-04-04 09:19:12 -0700102 bool muted;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800103
104 struct audio_device *dev;
105};
106
107struct stream_in {
108 struct audio_stream_in stream;
Eric Laurent150dbfe2013-02-27 14:31:02 -0800109 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800110 struct pcm_config config;
111 struct pcm *pcm;
112 int standby;
113 int source;
114 int pcm_device_id;
115 int device;
116 audio_channel_mask_t channel_mask;
117 audio_usecase_t usecase;
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700118 bool enable_aec;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800119
120 struct audio_device *dev;
121};
122
123typedef enum {
124 PCM_PLAYBACK,
125 PCM_CAPTURE,
126 VOICE_CALL
127} usecase_type_t;
128
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800129union stream_ptr {
130 struct stream_in *in;
131 struct stream_out *out;
132};
133
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800134struct audio_usecase {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800135 struct listnode list;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800136 audio_usecase_t id;
137 usecase_type_t type;
138 audio_devices_t devices;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700139 snd_device_t out_snd_device;
140 snd_device_t in_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800141 union stream_ptr stream;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800142};
143
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800144struct audio_device {
145 struct audio_hw_device device;
Eric Laurent150dbfe2013-02-27 14:31:02 -0800146 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800147 struct mixer *mixer;
148 audio_mode_t mode;
149 audio_devices_t out_device;
Eric Laurentc8400632013-02-14 19:04:54 -0800150 struct stream_in *active_input;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800151 struct stream_out *primary_output;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800152 bool bluetooth_nrec;
153 bool screen_off;
Eric Laurentb23d5282013-05-14 15:27:20 -0700154 int *snd_dev_ref_cnt;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800155 struct listnode usecase_list;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800156 struct audio_route *audio_route;
157 int acdb_settings;
Jean-Michel Trivic56336b2013-05-24 16:55:17 -0700158 bool speaker_lr_swap;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700159 struct voice voice;
Eric Laurentb23d5282013-05-14 15:27:20 -0700160 void *platform;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800161};
162
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700163int select_devices(struct audio_device *adev,
164 audio_usecase_t uc_id);
165int disable_audio_route(struct audio_device *adev,
166 struct audio_usecase *usecase,
167 bool update_mixer);
168int disable_snd_device(struct audio_device *adev,
169 snd_device_t snd_device,
170 bool update_mixer);
171struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
172 audio_usecase_t uc_id);
Eric Laurent150dbfe2013-02-27 14:31:02 -0800173/*
174 * NOTE: when multiple mutexes have to be acquired, always take the
175 * stream_in or stream_out mutex first, followed by the audio_device mutex.
176 */
177
Eric Laurentb23d5282013-05-14 15:27:20 -0700178#endif // QCOM_AUDIO_HW_H