Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 1 | /* |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 2 | * Copyright (c) 2013, The Linux Foundation. All rights reserved. |
| 3 | * Not a contribution. |
| 4 | * |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 5 | * 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 Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 20 | #ifndef QCOM_AUDIO_HW_H |
| 21 | #define QCOM_AUDIO_HW_H |
| 22 | |
| 23 | #include <cutils/list.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 24 | #include <hardware/audio.h> |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 25 | #include <tinyalsa/asoundlib.h> |
| 26 | |
| 27 | #include <audio_route/audio_route.h> |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 28 | #include "voice.h" |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 29 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 30 | /* Flags used to initialize acdb_settings variable that goes to ACDB library */ |
| 31 | #define DMIC_FLAG 0x00000002 |
Mingming Yin | 8e5a4f6 | 2013-10-07 15:23:41 -0700 | [diff] [blame] | 32 | #define QMIC_FLAG 0x00000004 |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 33 | #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 Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 39 | #define ACDB_DEV_TYPE_OUT 1 |
| 40 | #define ACDB_DEV_TYPE_IN 2 |
| 41 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 42 | #define MAX_SUPPORTED_CHANNEL_MASKS 2 |
Ravi Kumar Alamanda | 72c411f | 2013-02-12 02:09:33 -0800 | [diff] [blame] | 43 | |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 44 | typedef int snd_device_t; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 45 | |
| 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 | */ |
| 50 | typedef 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 Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 56 | /* FM usecase */ |
| 57 | USECASE_AUDIO_PLAYBACK_FM, |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 58 | |
| 59 | /* Capture usecases */ |
| 60 | USECASE_AUDIO_RECORD, |
| 61 | USECASE_AUDIO_RECORD_LOW_LATENCY, |
| 62 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 63 | /* Voice usecase */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 64 | USECASE_VOICE_CALL, |
| 65 | |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 66 | /* Voice extension usecases */ |
| 67 | USECASE_VOICE2_CALL, |
| 68 | USECASE_VOLTE_CALL, |
| 69 | USECASE_QCHAT_CALL, |
| 70 | |
Shiv Maliyappanahalli | da10764 | 2013-10-17 11:16:13 -0700 | [diff] [blame^] | 71 | USECASE_INCALL_REC_UPLINK, |
| 72 | USECASE_INCALL_REC_DOWNLINK, |
| 73 | USECASE_INCALL_REC_UPLINK_AND_DOWNLINK, |
| 74 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 75 | AUDIO_USECASE_MAX |
| 76 | } audio_usecase_t; |
| 77 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 78 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 79 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 80 | /* |
| 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 Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 88 | |
| 89 | struct stream_out { |
| 90 | struct audio_stream_out stream; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 91 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 92 | 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 Laurent | a9024de | 2013-04-04 09:19:12 -0700 | [diff] [blame] | 102 | bool muted; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 103 | |
| 104 | struct audio_device *dev; |
| 105 | }; |
| 106 | |
| 107 | struct stream_in { |
| 108 | struct audio_stream_in stream; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 109 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 110 | 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 Alamanda | f70ffb4 | 2013-04-16 15:55:53 -0700 | [diff] [blame] | 118 | bool enable_aec; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 119 | |
| 120 | struct audio_device *dev; |
| 121 | }; |
| 122 | |
| 123 | typedef enum { |
| 124 | PCM_PLAYBACK, |
| 125 | PCM_CAPTURE, |
| 126 | VOICE_CALL |
| 127 | } usecase_type_t; |
| 128 | |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 129 | union stream_ptr { |
| 130 | struct stream_in *in; |
| 131 | struct stream_out *out; |
| 132 | }; |
| 133 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 134 | struct audio_usecase { |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 135 | struct listnode list; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 136 | audio_usecase_t id; |
| 137 | usecase_type_t type; |
| 138 | audio_devices_t devices; |
Ravi Kumar Alamanda | 71c84b7 | 2013-03-10 23:50:28 -0700 | [diff] [blame] | 139 | snd_device_t out_snd_device; |
| 140 | snd_device_t in_snd_device; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 141 | union stream_ptr stream; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 142 | }; |
| 143 | |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 144 | struct audio_device { |
| 145 | struct audio_hw_device device; |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 146 | pthread_mutex_t lock; /* see note below on mutex acquisition order */ |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 147 | struct mixer *mixer; |
| 148 | audio_mode_t mode; |
| 149 | audio_devices_t out_device; |
Eric Laurent | c840063 | 2013-02-14 19:04:54 -0800 | [diff] [blame] | 150 | struct stream_in *active_input; |
Ravi Kumar Alamanda | 096c87f | 2013-02-28 20:54:57 -0800 | [diff] [blame] | 151 | struct stream_out *primary_output; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 152 | bool bluetooth_nrec; |
| 153 | bool screen_off; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 154 | int *snd_dev_ref_cnt; |
Ravi Kumar Alamanda | 3b1816c | 2013-02-27 23:01:21 -0800 | [diff] [blame] | 155 | struct listnode usecase_list; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 156 | struct audio_route *audio_route; |
| 157 | int acdb_settings; |
Jean-Michel Trivi | c56336b | 2013-05-24 16:55:17 -0700 | [diff] [blame] | 158 | bool speaker_lr_swap; |
Shiv Maliyappanahalli | 34b585f | 2013-10-01 15:49:05 -0700 | [diff] [blame] | 159 | struct voice voice; |
Eric Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 160 | void *platform; |
Ravi Kumar Alamanda | 2dfba2b | 2013-01-17 16:50:22 -0800 | [diff] [blame] | 161 | }; |
| 162 | |
Apoorv Raghuvanshi | 6e26284 | 2013-10-06 14:39:35 -0700 | [diff] [blame] | 163 | int select_devices(struct audio_device *adev, |
| 164 | audio_usecase_t uc_id); |
| 165 | int disable_audio_route(struct audio_device *adev, |
| 166 | struct audio_usecase *usecase, |
| 167 | bool update_mixer); |
| 168 | int disable_snd_device(struct audio_device *adev, |
| 169 | snd_device_t snd_device, |
| 170 | bool update_mixer); |
| 171 | struct audio_usecase *get_usecase_from_list(struct audio_device *adev, |
| 172 | audio_usecase_t uc_id); |
Eric Laurent | 150dbfe | 2013-02-27 14:31:02 -0800 | [diff] [blame] | 173 | /* |
| 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 Laurent | b23d528 | 2013-05-14 15:27:20 -0700 | [diff] [blame] | 178 | #endif // QCOM_AUDIO_HW_H |