vivek mehta | 62dd1dc | 2016-03-03 17:23:38 -0800 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright (C) 2016 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #define LOG_TAG "hardware_info" |
| 18 | /*#define LOG_NDEBUG 0*/ |
| 19 | #define LOG_NDDEBUG 0 |
| 20 | |
| 21 | #include <stdlib.h> |
| 22 | #include <cutils/log.h> |
| 23 | #include "audio_hw.h" |
| 24 | #include "platform.h" |
| 25 | #include "audio_extn.h" |
| 26 | |
| 27 | struct hardware_info { |
| 28 | char name[HW_INFO_ARRAY_MAX_SIZE]; |
| 29 | char type[HW_INFO_ARRAY_MAX_SIZE]; |
| 30 | /* variables for handling target variants */ |
| 31 | uint32_t num_snd_devices; |
| 32 | char dev_extn[HW_INFO_ARRAY_MAX_SIZE]; |
| 33 | snd_device_t *snd_devices; |
| 34 | }; |
| 35 | |
| 36 | #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) |
| 37 | |
| 38 | |
| 39 | static const snd_device_t tasha_db_variant_devices[] = { |
| 40 | SND_DEVICE_OUT_SPEAKER |
| 41 | }; |
| 42 | |
| 43 | static const snd_device_t tasha_fluid_variant_devices[] = { |
| 44 | SND_DEVICE_OUT_SPEAKER, |
| 45 | SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES, |
| 46 | SND_DEVICE_OUT_VOICE_SPEAKER, |
| 47 | SND_DEVICE_OUT_SPEAKER_AND_HDMI, |
| 48 | SND_DEVICE_OUT_SPEAKER_PROTECTED, |
| 49 | SND_DEVICE_OUT_VOICE_SPEAKER_PROTECTED, |
| 50 | }; |
| 51 | |
| 52 | static const snd_device_t tasha_liquid_variant_devices[] = { |
| 53 | SND_DEVICE_OUT_SPEAKER, |
| 54 | SND_DEVICE_OUT_SPEAKER_AND_HEADPHONES, |
| 55 | SND_DEVICE_IN_SPEAKER_MIC, |
| 56 | SND_DEVICE_IN_HEADSET_MIC, |
| 57 | SND_DEVICE_IN_VOICE_DMIC, |
| 58 | SND_DEVICE_IN_VOICE_SPEAKER_DMIC, |
| 59 | SND_DEVICE_IN_VOICE_REC_DMIC_STEREO, |
| 60 | SND_DEVICE_IN_VOICE_REC_DMIC_FLUENCE, |
| 61 | SND_DEVICE_IN_QUAD_MIC, |
| 62 | }; |
| 63 | |
| 64 | struct snd_card_split cur_snd_card_split = { |
| 65 | .device = {0}, |
| 66 | .snd_card = {0}, |
| 67 | .form_factor = {0}, |
| 68 | }; |
| 69 | |
| 70 | static void update_hardware_info_8996(struct hardware_info *hw_info) |
| 71 | { |
| 72 | struct snd_card_split *tmp_handle = get_snd_card_split(); |
| 73 | ALOGV("%s: device %s snd_card %s form_factor %s", |
| 74 | __func__, tmp_handle->device, tmp_handle->snd_card, tmp_handle->form_factor); |
| 75 | |
| 76 | strlcpy(hw_info->name, tmp_handle->device, sizeof(hw_info->name)); |
| 77 | snprintf(hw_info->type, sizeof(hw_info->type), " %s", tmp_handle->form_factor); |
| 78 | snprintf(hw_info->dev_extn, sizeof(hw_info->dev_extn), "-%s", tmp_handle->form_factor); |
| 79 | |
| 80 | if (!strncmp(tmp_handle->form_factor, "fluid", sizeof("fluid"))) { |
| 81 | hw_info->snd_devices = (snd_device_t *)tasha_fluid_variant_devices; |
| 82 | hw_info->num_snd_devices = ARRAY_SIZE(tasha_fluid_variant_devices); |
| 83 | } else if (!strncmp(tmp_handle->form_factor, "liquid", sizeof("liquid"))) { |
| 84 | hw_info->snd_devices = (snd_device_t *)tasha_liquid_variant_devices; |
| 85 | hw_info->num_snd_devices = ARRAY_SIZE(tasha_liquid_variant_devices); |
| 86 | } else if (!strncmp(tmp_handle->form_factor, "db", sizeof("db"))) { |
| 87 | hw_info->snd_devices = (snd_device_t *)tasha_db_variant_devices; |
| 88 | hw_info->num_snd_devices = ARRAY_SIZE(tasha_db_variant_devices); |
| 89 | } else { |
| 90 | ALOGW("%s: %s form factor doesnt need mixer path over ride", __func__, tmp_handle->form_factor); |
| 91 | } |
| 92 | |
| 93 | ALOGV("name %s type %s dev_extn %s", hw_info->name, hw_info->type, hw_info->dev_extn); |
| 94 | } |
| 95 | |
| 96 | |
| 97 | void *hw_info_init(const char *snd_card_name) |
| 98 | { |
| 99 | struct hardware_info *hw_info = NULL; |
| 100 | bool hw_supported = false; |
| 101 | |
| 102 | if (strstr(snd_card_name, "msm8996")) { |
| 103 | ALOGD("8996 - variant soundcard"); |
| 104 | hw_supported = true; |
| 105 | } else { |
| 106 | ALOGE("%s: Unsupported target %s:",__func__, snd_card_name); |
| 107 | } |
| 108 | |
| 109 | if (hw_supported) { |
| 110 | hw_info = malloc(sizeof(struct hardware_info)); |
| 111 | if (!hw_info) { |
| 112 | ALOGE("failed to allocate mem for hardware info"); |
| 113 | goto on_finish; |
| 114 | } |
| 115 | |
| 116 | hw_info->snd_devices = NULL; |
| 117 | hw_info->num_snd_devices = 0; |
| 118 | strlcpy(hw_info->dev_extn, "", sizeof(hw_info->dev_extn)); |
| 119 | strlcpy(hw_info->type, "", sizeof(hw_info->type)); |
| 120 | strlcpy(hw_info->name, "", sizeof(hw_info->name)); |
| 121 | update_hardware_info_8996(hw_info); |
| 122 | } |
| 123 | |
| 124 | on_finish: |
| 125 | return hw_info; |
| 126 | } |
| 127 | |
| 128 | void hw_info_deinit(void *hw_info) |
| 129 | { |
| 130 | free(hw_info); |
| 131 | } |
| 132 | |
| 133 | void hw_info_append_hw_type(void *hw_info, snd_device_t snd_device, |
| 134 | char *device_name) |
| 135 | { |
| 136 | struct hardware_info *my_data = (struct hardware_info*) hw_info; |
| 137 | uint32_t i = 0; |
| 138 | |
| 139 | snd_device_t *snd_devices = |
| 140 | (snd_device_t *) my_data->snd_devices; |
| 141 | |
| 142 | if (snd_devices != NULL) { |
| 143 | for (i = 0; i < my_data->num_snd_devices; i++) { |
| 144 | if (snd_device == (snd_device_t)snd_devices[i]) { |
| 145 | ALOGV("extract dev_extn device %d, device_name %s extn = %s ", |
| 146 | (snd_device_t)snd_devices[i], device_name, my_data->dev_extn); |
| 147 | CHECK(strlcat(device_name, my_data->dev_extn, |
| 148 | DEVICE_NAME_MAX_SIZE) < DEVICE_NAME_MAX_SIZE); |
| 149 | break; |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | ALOGD("%s : device_name = %s", __func__,device_name); |
| 154 | } |
| 155 | |
| 156 | struct snd_card_split *get_snd_card_split() |
| 157 | { |
| 158 | return &cur_snd_card_split; |
| 159 | } |
| 160 | |
| 161 | void set_snd_card_split(const char* in_snd_card_name) |
| 162 | { |
| 163 | /* sound card name follows below mentioned convention |
| 164 | <target name>-<sound card name>-<form factor>-snd-card |
| 165 | parse target name, sound card name and form factor |
| 166 | */ |
| 167 | char *snd_card_name = strdup(in_snd_card_name); |
| 168 | char *tmp = NULL; |
| 169 | char *device = NULL; |
| 170 | char *snd_card = NULL; |
| 171 | char *form_factor = NULL; |
| 172 | |
| 173 | if (in_snd_card_name == NULL) { |
| 174 | ALOGE("%s: snd_card_name passed is NULL", __func__); |
| 175 | goto on_error; |
| 176 | } |
| 177 | |
| 178 | device = strtok_r(snd_card_name, "-", &tmp); |
| 179 | if (device == NULL) { |
| 180 | ALOGE("%s: called on invalid snd card name", __func__); |
| 181 | goto on_error; |
| 182 | } |
| 183 | strlcpy(cur_snd_card_split.device, device, HW_INFO_ARRAY_MAX_SIZE); |
| 184 | |
| 185 | snd_card = strtok_r(NULL, "-", &tmp); |
| 186 | if (snd_card == NULL) { |
| 187 | ALOGE("%s: called on invalid snd card name", __func__); |
| 188 | goto on_error; |
| 189 | } |
| 190 | strlcpy(cur_snd_card_split.snd_card, snd_card, HW_INFO_ARRAY_MAX_SIZE); |
| 191 | |
| 192 | form_factor = strtok_r(NULL, "-", &tmp); |
| 193 | if (form_factor == NULL) { |
| 194 | ALOGE("%s: called on invalid snd card name", __func__); |
| 195 | goto on_error; |
| 196 | } |
| 197 | strlcpy(cur_snd_card_split.form_factor, form_factor, HW_INFO_ARRAY_MAX_SIZE); |
| 198 | |
| 199 | ALOGV("%s: snd_card_name(%s) device(%s) snd_card(%s) form_factor(%s)", |
| 200 | __func__, in_snd_card_name, device, snd_card, form_factor); |
| 201 | |
| 202 | on_error: |
| 203 | if (snd_card_name) |
| 204 | free(snd_card_name); |
| 205 | } |
| 206 | |