• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <cutils/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 
update_hardware_info_8x16(struct hardware_info * hw_info,const char * snd_card_name)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, "msm8952-snd-card") ||
51                 !strcmp(snd_card_name, "msm8952-snd-card-mtp")) {
52         strlcpy(hw_info->name, "msm8952", sizeof(hw_info->name));
53     }  else if (!strcmp(snd_card_name, "msm8952-l9300-snd-card")) {
54         strlcpy(hw_info->name, "msm8952", sizeof(hw_info->name));
55     } else {
56         ALOGW("%s: Not an  8x16/8909/8952 device", __func__);
57     }
58 }
59 
hw_info_init(const char * snd_card_name)60 void *hw_info_init(const char *snd_card_name)
61 {
62     struct hardware_info *hw_info;
63 
64     hw_info = malloc(sizeof(struct hardware_info));
65     if (!hw_info) {
66         ALOGE("failed to allocate mem for hardware info");
67         return NULL;
68     }
69 
70     if (strstr(snd_card_name, "msm8x16") || strstr(snd_card_name, "msm8909")
71         || strstr(snd_card_name, "msm8952")) {
72         ALOGV("8x16 - variant soundcard");
73 
74         strlcpy(hw_info->type, "", sizeof(hw_info->type));
75         strlcpy(hw_info->name, "", sizeof(hw_info->name));
76         hw_info->snd_devices = NULL;
77         hw_info->num_snd_devices = 0;
78         strlcpy(hw_info->dev_extn, "", sizeof(hw_info->dev_extn));
79 
80         update_hardware_info_8x16(hw_info, snd_card_name);
81     } else {
82         ALOGE("%s: Unsupported target %s:",__func__, snd_card_name);
83         free(hw_info);
84         hw_info = NULL;
85     }
86 
87     return hw_info;
88 }
89 
hw_info_deinit(void * hw_info)90 void hw_info_deinit(void *hw_info)
91 {
92     struct hardware_info *my_data = (struct hardware_info*) hw_info;
93 
94     if(my_data)
95         free(my_data);
96 }
97 
hw_info_append_hw_type(void * hw_info,snd_device_t snd_device,char * device_name)98 void hw_info_append_hw_type(void *hw_info, snd_device_t snd_device,
99                             char *device_name)
100 {
101     struct hardware_info *my_data = (struct hardware_info*) hw_info;
102     uint32_t i = 0;
103 
104     if (my_data == NULL)
105         return;
106 
107     snd_device_t *snd_devices =
108             (snd_device_t *) my_data->snd_devices;
109 
110     if(snd_devices != NULL) {
111         for (i = 0; i <  my_data->num_snd_devices; i++) {
112             if (snd_device == (snd_device_t)snd_devices[i]) {
113                 ALOGV("extract dev_extn device %d, extn = %s",
114                         (snd_device_t)snd_devices[i],  my_data->dev_extn);
115                 CHECK(strlcat(device_name,  my_data->dev_extn,
116                         DEVICE_NAME_MAX_SIZE) < DEVICE_NAME_MAX_SIZE);
117                 break;
118             }
119         }
120     }
121     ALOGD("%s : device_name = %s", __func__,device_name);
122 }
123