blob: 2eb16162047520b1204788bbeb3a661527c7c09b [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
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080071 AUDIO_USECASE_MAX
72} audio_usecase_t;
73
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080074#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
75
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080076/*
77 * tinyAlsa library interprets period size as number of frames
78 * one frame = channel_count * sizeof (pcm sample)
79 * so if format = 16-bit PCM and channels = Stereo, frame size = 2 ch * 2 = 4 bytes
80 * DEEP_BUFFER_OUTPUT_PERIOD_SIZE = 1024 means 1024 * 4 = 4096 bytes
81 * We should take care of returning proper size when AudioFlinger queries for
82 * the buffer size of an input/output stream
83 */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080084
85struct stream_out {
86 struct audio_stream_out stream;
Eric Laurent150dbfe2013-02-27 14:31:02 -080087 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080088 struct pcm_config config;
89 struct pcm *pcm;
90 int standby;
91 int pcm_device_id;
92 audio_channel_mask_t channel_mask;
93 audio_devices_t devices;
94 audio_output_flags_t flags;
95 audio_usecase_t usecase;
96 /* Array of supported channel mask configurations. +1 so that the last entry is always 0 */
97 audio_channel_mask_t supported_channel_masks[MAX_SUPPORTED_CHANNEL_MASKS + 1];
Eric Laurenta9024de2013-04-04 09:19:12 -070098 bool muted;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -080099
100 struct audio_device *dev;
101};
102
103struct stream_in {
104 struct audio_stream_in stream;
Eric Laurent150dbfe2013-02-27 14:31:02 -0800105 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800106 struct pcm_config config;
107 struct pcm *pcm;
108 int standby;
109 int source;
110 int pcm_device_id;
111 int device;
112 audio_channel_mask_t channel_mask;
113 audio_usecase_t usecase;
Ravi Kumar Alamandaf70ffb42013-04-16 15:55:53 -0700114 bool enable_aec;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800115
116 struct audio_device *dev;
117};
118
119typedef enum {
120 PCM_PLAYBACK,
121 PCM_CAPTURE,
122 VOICE_CALL
123} usecase_type_t;
124
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800125union stream_ptr {
126 struct stream_in *in;
127 struct stream_out *out;
128};
129
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800130struct audio_usecase {
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800131 struct listnode list;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800132 audio_usecase_t id;
133 usecase_type_t type;
134 audio_devices_t devices;
Ravi Kumar Alamanda71c84b72013-03-10 23:50:28 -0700135 snd_device_t out_snd_device;
136 snd_device_t in_snd_device;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800137 union stream_ptr stream;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800138};
139
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800140struct audio_device {
141 struct audio_hw_device device;
Eric Laurent150dbfe2013-02-27 14:31:02 -0800142 pthread_mutex_t lock; /* see note below on mutex acquisition order */
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800143 struct mixer *mixer;
144 audio_mode_t mode;
145 audio_devices_t out_device;
Eric Laurentc8400632013-02-14 19:04:54 -0800146 struct stream_in *active_input;
Ravi Kumar Alamanda096c87f2013-02-28 20:54:57 -0800147 struct stream_out *primary_output;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800148 bool bluetooth_nrec;
149 bool screen_off;
Eric Laurentb23d5282013-05-14 15:27:20 -0700150 int *snd_dev_ref_cnt;
Ravi Kumar Alamanda3b1816c2013-02-27 23:01:21 -0800151 struct listnode usecase_list;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800152 struct audio_route *audio_route;
153 int acdb_settings;
Jean-Michel Trivic56336b2013-05-24 16:55:17 -0700154 bool speaker_lr_swap;
Shiv Maliyappanahalli34b585f2013-10-01 15:49:05 -0700155 struct voice voice;
Eric Laurentb23d5282013-05-14 15:27:20 -0700156 void *platform;
Ravi Kumar Alamanda2dfba2b2013-01-17 16:50:22 -0800157};
158
Apoorv Raghuvanshi6e262842013-10-06 14:39:35 -0700159int select_devices(struct audio_device *adev,
160 audio_usecase_t uc_id);
161int disable_audio_route(struct audio_device *adev,
162 struct audio_usecase *usecase,
163 bool update_mixer);
164int disable_snd_device(struct audio_device *adev,
165 snd_device_t snd_device,
166 bool update_mixer);
167struct audio_usecase *get_usecase_from_list(struct audio_device *adev,
168 audio_usecase_t uc_id);
Eric Laurent150dbfe2013-02-27 14:31:02 -0800169/*
170 * NOTE: when multiple mutexes have to be acquired, always take the
171 * stream_in or stream_out mutex first, followed by the audio_device mutex.
172 */
173
Eric Laurentb23d5282013-05-14 15:27:20 -0700174#endif // QCOM_AUDIO_HW_H