blob: ac5d094b294e21e7976f8c64127ea7d1bda3dea0 [file] [log] [blame]
Uday Kiran Pichika2d3a3072018-06-04 16:42:13 +05301/*
Tharaga Balachandranc3987962020-01-23 18:36:49 -05002 * Copyright (c) 2013, 2018, 2020 The Linux Foundation. All rights reserved.
Uday Kiran Pichika2d3a3072018-06-04 16:42:13 +05303
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 * * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * * Redistributions in binary form must reproduce the above
10 * copyright notice, this list of conditions and the following
11 * disclaimer in the documentation and/or other materials provided
12 * with the distribution.
13 * * Neither the name of The Linux Foundation nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
25 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
26 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
27 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
30#include <unistd.h>
31#include <gralloc_priv.h>
32#include "qd_utils.h"
33
34static const int kFBNodeMax = 4;
35namespace qdutils {
36
Mohan Pallaka5d814432018-08-01 10:40:13 -070037static int parseLine(char *input, char *tokens[], const uint32_t maxToken, uint32_t *count) {
38 char *tmpToken = NULL;
39 char *tmpPtr;
40 uint32_t index = 0;
41 const char *delim = ", =\n";
42 if (!input) {
43 return -1;
44 }
45 tmpToken = strtok_r(input, delim, &tmpPtr);
46 while (tmpToken && index < maxToken) {
47 tokens[index++] = tmpToken;
48 tmpToken = strtok_r(NULL, delim, &tmpPtr);
49 }
50 *count = index;
51
52 return 0;
53}
54
Uday Kiran Pichika2d3a3072018-06-04 16:42:13 +053055static int getExternalNode(const char *type) {
56 FILE *displayDeviceFP = NULL;
57 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
58 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
59 int j = 0;
60
61 for(j = 0; j < kFBNodeMax; j++) {
62 snprintf (msmFbTypePath, sizeof(msmFbTypePath),
63 "/sys/devices/virtual/graphics/fb%d/msm_fb_type", j);
64 displayDeviceFP = fopen(msmFbTypePath, "r");
65 if(displayDeviceFP) {
66 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
67 displayDeviceFP);
68 if(strncmp(fbType, type, strlen(type)) == 0) {
69 ALOGD("%s: %s is at fb%d", __func__, type, j);
70 fclose(displayDeviceFP);
71 break;
72 }
73 fclose(displayDeviceFP);
74 } else {
75 ALOGE("%s: Failed to open fb node %s", __func__, msmFbTypePath);
76 }
77 }
78
79 if (j < kFBNodeMax)
80 return j;
81 else
82 ALOGE("%s: Failed to find %s node", __func__, type);
83
84 return -1;
85}
86
87int getHDMINode(void) {
88 return getExternalNode("dtv panel");
89}
90
91int getEdidRawData(char *buffer)
92{
93 int size;
94 int edidFile;
95 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
96 int node_id = getHDMINode();
97
98 if (node_id < 0) {
99 ALOGE("%s no HDMI node found", __func__);
100 return 0;
101 }
102
103 snprintf(msmFbTypePath, sizeof(msmFbTypePath),
104 "/sys/devices/virtual/graphics/fb%d/edid_raw_data", node_id);
105
106 edidFile = open(msmFbTypePath, O_RDONLY, 0);
107
108 if (edidFile < 0) {
109 ALOGE("%s no edid raw data found %s", __func__,msmFbTypePath);
110 return 0;
111 }
112
113 size = (int)read(edidFile, (char*)buffer, EDID_RAW_DATA_SIZE);
114 close(edidFile);
115 return size;
116}
117
Mohan Pallaka5d814432018-08-01 10:40:13 -0700118bool isDPConnected() {
119 char connectPath[MAX_FRAME_BUFFER_NAME_SIZE];
120 FILE *connectFile = NULL;
121 size_t len = MAX_STRING_LENGTH;
122 char stringBuffer[MAX_STRING_LENGTH];
123 char *line = stringBuffer;
124
125 int nodeId = getExternalNode("dp panel");
126 if (nodeId < 0) {
127 ALOGE("%s no DP node found", __func__);
128 return false;
129 }
130
131 snprintf(connectPath, sizeof(connectPath),
132 "/sys/devices/virtual/graphics/fb%d/connected", nodeId);
133
134 connectFile = fopen(connectPath, "rb");
135 if (!connectFile) {
136 ALOGW("Failed to open connect node for device node %s", connectPath);
137 return false;
138 }
139
140 if (getline(&line, &len, connectFile) < 0) {
141 fclose(connectFile);
142 return false;
143 }
144
145 fclose(connectFile);
146
147 return atoi(line);
148}
149
150int getDPTestConfig(uint32_t *panelBpp, uint32_t *patternType) {
151 if (!panelBpp || !patternType) {
152 return -1;
153 }
154
155 char configPath[MAX_FRAME_BUFFER_NAME_SIZE];
156 FILE *configFile = NULL;
157 uint32_t tokenCount = 0;
158 const uint32_t maxCount = 10;
159 char *tokens[maxCount] = { NULL };
160 size_t len = MAX_STRING_LENGTH;
161 char stringBuffer[MAX_STRING_LENGTH];
162 char *line = stringBuffer;
163
164 int nodeId = getExternalNode("dp panel");
165 if (nodeId < 0) {
166 ALOGE("%s no DP node found", __func__);
167 return -EINVAL;
168 }
169
170 snprintf(configPath, sizeof(configPath),
171 "/sys/devices/virtual/graphics/fb%d/config", nodeId);
172
173 configFile = fopen(configPath, "rb");
174 if (!configFile) {
175 ALOGW("Failed to open config node for device node %s", configPath);
176 return -EINVAL;
177 }
178
179 while (getline(&line, &len, configFile) != -1) {
180 if (!parseLine(line, tokens, maxCount, &tokenCount)) {
181 if (tokens[0] != NULL) {
182 if (!strncmp(tokens[0], "bpp", strlen("bpp"))) {
183 *panelBpp = static_cast<uint32_t>(atoi(tokens[1]));
184 } else if (!strncmp(tokens[0], "pattern", strlen("pattern"))) {
185 *patternType = static_cast<uint32_t>(atoi(tokens[1]));
186 }
187 }
188 }
189 }
190
191 fclose(configFile);
192
193 return 0;
194}
195
196DriverType getDriverType() {
197 const char *fb_caps = "/sys/devices/virtual/graphics/fb0/mdp/caps";
198 // 0 - File exists
199 return access(fb_caps, F_OK) ? DriverType::DRM : DriverType::FB;
200}
201
202const char *GetHALPixelFormatString(int format) {
203 switch (format) {
204 case HAL_PIXEL_FORMAT_RGBA_8888:
205 return "RGBA_8888";
206 case HAL_PIXEL_FORMAT_RGBX_8888:
207 return "RGBX_8888";
208 case HAL_PIXEL_FORMAT_RGB_888:
209 return "RGB_888";
210 case HAL_PIXEL_FORMAT_RGB_565:
211 return "RGB_565";
212 case HAL_PIXEL_FORMAT_BGR_565:
213 return "BGR_565";
214 case HAL_PIXEL_FORMAT_BGRA_8888:
215 return "BGRA_8888";
216 case HAL_PIXEL_FORMAT_RGBA_5551:
217 return "RGBA_5551";
218 case HAL_PIXEL_FORMAT_RGBA_4444:
219 return "RGBA_4444";
220 case HAL_PIXEL_FORMAT_YV12:
221 return "YV12";
222 case HAL_PIXEL_FORMAT_YCbCr_422_SP:
223 return "YCbCr_422_SP_NV16";
224 case HAL_PIXEL_FORMAT_YCrCb_420_SP:
225 return "YCrCb_420_SP_NV21";
226 case HAL_PIXEL_FORMAT_YCbCr_422_I:
227 return "YCbCr_422_I_YUY2";
228 case HAL_PIXEL_FORMAT_YCrCb_422_I:
229 return "YCrCb_422_I_YVYU";
230 case HAL_PIXEL_FORMAT_NV12_ENCODEABLE:
231 return "NV12_ENCODEABLE";
232 case HAL_PIXEL_FORMAT_YCbCr_420_SP_TILED:
233 return "YCbCr_420_SP_TILED_TILE_4x2";
234 case HAL_PIXEL_FORMAT_YCbCr_420_SP:
235 return "YCbCr_420_SP";
236 case HAL_PIXEL_FORMAT_YCrCb_420_SP_ADRENO:
237 return "YCrCb_420_SP_ADRENO";
238 case HAL_PIXEL_FORMAT_YCrCb_422_SP:
239 return "YCrCb_422_SP";
240 case HAL_PIXEL_FORMAT_R_8:
241 return "R_8";
242 case HAL_PIXEL_FORMAT_RG_88:
243 return "RG_88";
244 case HAL_PIXEL_FORMAT_INTERLACE:
245 return "INTERLACE";
246 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS:
247 return "YCbCr_420_SP_VENUS";
248 case HAL_PIXEL_FORMAT_YCrCb_420_SP_VENUS:
249 return "YCrCb_420_SP_VENUS";
250 case HAL_PIXEL_FORMAT_YCbCr_420_SP_VENUS_UBWC:
251 return "YCbCr_420_SP_VENUS_UBWC";
252 case HAL_PIXEL_FORMAT_RGBA_1010102:
253 return "RGBA_1010102";
254 case HAL_PIXEL_FORMAT_ARGB_2101010:
255 return "ARGB_2101010";
256 case HAL_PIXEL_FORMAT_RGBX_1010102:
257 return "RGBX_1010102";
258 case HAL_PIXEL_FORMAT_XRGB_2101010:
259 return "XRGB_2101010";
260 case HAL_PIXEL_FORMAT_BGRA_1010102:
261 return "BGRA_1010102";
262 case HAL_PIXEL_FORMAT_ABGR_2101010:
263 return "ABGR_2101010";
264 case HAL_PIXEL_FORMAT_BGRX_1010102:
265 return "BGRX_1010102";
266 case HAL_PIXEL_FORMAT_XBGR_2101010:
267 return "XBGR_2101010";
268 case HAL_PIXEL_FORMAT_YCbCr_420_P010:
269 return "YCbCr_420_P010";
270 case HAL_PIXEL_FORMAT_YCbCr_420_TP10_UBWC:
271 return "YCbCr_420_TP10_UBWC";
272 case HAL_PIXEL_FORMAT_YCbCr_420_P010_VENUS:
273 return "YCbCr_420_P010_VENUS";
274 default:
275 return "Unknown_format";
276 }
277}
278
Uday Kiran Pichika2d3a3072018-06-04 16:42:13 +0530279}; //namespace qdutils