Home | History | Annotate | Download | only in msm8916
      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 <dlfcn.h>
     23 #include <log/log.h>
     24 #include <cutils/str_parms.h>
     25 #include "audio_hw.h"
     26 #include "platform.h"
     27 #include "platform_api.h"
     28 
     29 
     30 struct hardware_info {
     31     char name[HW_INFO_ARRAY_MAX_SIZE];
     32     char type[HW_INFO_ARRAY_MAX_SIZE];
     33     /* variables for handling target variants */
     34     uint32_t num_snd_devices;
     35     char dev_extn[HW_INFO_ARRAY_MAX_SIZE];
     36     snd_device_t  *snd_devices;
     37 };
     38 
     39 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
     40 
     41 
     42 static void update_hardware_info_8x16(struct hardware_info *hw_info, const char *snd_card_name)
     43 {
     44     if (!strcmp(snd_card_name, "msm8x16-snd-card") ||
     45         !strcmp(snd_card_name, "msm8x16-snd-card-mtp")) {
     46         strlcpy(hw_info->name, "msm8x16", sizeof(hw_info->name));
     47     } else if (!strcmp(snd_card_name, "msm8909-snd-card") ||
     48                !strcmp(snd_card_name, "msm8909-pm8916-snd-card")) {
     49         strlcpy(hw_info->name, "msm8909", sizeof(hw_info->name));
     50     } else if (!strcmp(snd_card_name, "msm-bg-snd-card")) {
     51         strlcpy(hw_info->name, "msm8909", sizeof(hw_info->name));
     52     }  else if (!strcmp(snd_card_name, "msm8952-snd-card") ||
     53                 !strcmp(snd_card_name, "msm8952-snd-card-mtp")) {
     54         strlcpy(hw_info->name, "msm8952", sizeof(hw_info->name));
     55     }  else if (!strcmp(snd_card_name, "msm8952-l9300-snd-card")) {
     56         strlcpy(hw_info->name, "msm8952", sizeof(hw_info->name));
     57     } else {
     58         ALOGW("%s: Not an  8x16/8909/8952 device", __func__);
     59     }
     60 }
     61 
     62 void *hw_info_init(const char *snd_card_name)
     63 {
     64     struct hardware_info *hw_info;
     65 
     66     hw_info = malloc(sizeof(struct hardware_info));
     67     if (!hw_info) {
     68         ALOGE("failed to allocate mem for hardware info");
     69         return NULL;
     70     }
     71 
     72     if (strstr(snd_card_name, "msm8x16") || strstr(snd_card_name, "msm8909")
     73         || strstr(snd_card_name, "msm8952") ||
     74         strstr(snd_card_name, "msm-bg-snd-card")) {
     75         ALOGV("8x16 - variant soundcard");
     76 
     77         strlcpy(hw_info->type, "", sizeof(hw_info->type));
     78         strlcpy(hw_info->name, "", sizeof(hw_info->name));
     79         hw_info->snd_devices = NULL;
     80         hw_info->num_snd_devices = 0;
     81         strlcpy(hw_info->dev_extn, "", sizeof(hw_info->dev_extn));
     82 
     83         update_hardware_info_8x16(hw_info, snd_card_name);
     84     } else {
     85         ALOGE("%s: Unsupported target %s:",__func__, snd_card_name);
     86         free(hw_info);
     87         hw_info = NULL;
     88     }
     89 
     90     return hw_info;
     91 }
     92 
     93 void hw_info_deinit(void *hw_info)
     94 {
     95     struct hardware_info *my_data = (struct hardware_info*) hw_info;
     96 
     97     if(my_data)
     98         free(my_data);
     99 }
    100 
    101 void hw_info_append_hw_type(void *hw_info, snd_device_t snd_device,
    102                             char *device_name)
    103 {
    104     struct hardware_info *my_data = (struct hardware_info*) hw_info;
    105     uint32_t i = 0;
    106 
    107     if (my_data == NULL)
    108         return;
    109 
    110     snd_device_t *snd_devices =
    111             (snd_device_t *) my_data->snd_devices;
    112 
    113     if(snd_devices != NULL) {
    114         for (i = 0; i <  my_data->num_snd_devices; i++) {
    115             if (snd_device == (snd_device_t)snd_devices[i]) {
    116                 ALOGV("extract dev_extn device %d, extn = %s",
    117                         (snd_device_t)snd_devices[i],  my_data->dev_extn);
    118                 CHECK(strlcat(device_name,  my_data->dev_extn,
    119                         DEVICE_NAME_MAX_SIZE) < DEVICE_NAME_MAX_SIZE);
    120                 break;
    121             }
    122         }
    123     }
    124     ALOGD("%s : device_name = %s", __func__,device_name);
    125 }
    126