1 /*
2 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
3
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 #include <cutils/log.h>
30 #include <linux/msm_mdp.h>
31 #include "mdp_version.h"
32
33 #define DEBUG 0
34
35 ANDROID_SINGLETON_STATIC_INSTANCE(qdutils::MDPVersion);
36 namespace qdutils {
37
38 #define TOKEN_PARAMS_DELIM "="
39
40 #ifndef MDSS_MDP_HW_REV_100
41 #define MDSS_MDP_HW_REV_100 0x10000000 //8974 v1
42 #endif
43 #ifndef MDSS_MDP_HW_REV_101
44 #define MDSS_MDP_HW_REV_101 0x10010000 //8x26
45 #endif
46 #ifndef MDSS_MDP_HW_REV_102
47 #define MDSS_MDP_HW_REV_102 0x10020000 //8974 v2
48 #endif
49 #ifndef MDSS_MDP_HW_REV_103
50 #define MDSS_MDP_HW_REV_103 0x10030000 //8084
51 #endif
52 #ifndef MDSS_MDP_HW_REV_104
53 #define MDSS_MDP_HW_REV_104 0x10040000 //Next version
54 #endif
55 #ifndef MDSS_MDP_HW_REV_105
56 #define MDSS_MDP_HW_REV_105 0x10050000 //Next version
57 #endif
58 #ifndef MDSS_MDP_HW_REV_106
59 #define MDSS_MDP_HW_REV_106 0x10060000 //8x16
60 #endif
61 #ifndef MDSS_MDP_HW_REV_107
62 #define MDSS_MDP_HW_REV_107 0x10070000 //Next version
63 #endif
64 #ifndef MDSS_MDP_HW_REV_200
65 #define MDSS_MDP_HW_REV_200 0x20000000 //8092
66 #endif
67 #ifndef MDSS_MDP_HW_REV_206
68 #define MDSS_MDP_HW_REV_206 0x20060000 //Future
69 #endif
70
MDPVersion()71 MDPVersion::MDPVersion()
72 {
73 mMDPVersion = MDSS_V5;
74 mMdpRev = 0;
75 mRGBPipes = 0;
76 mVGPipes = 0;
77 mDMAPipes = 0;
78 mFeatures = 0;
79 mMDPUpscale = 0;
80 mMDPDownscale = 0;
81 mMacroTileEnabled = false;
82 mLowBw = 0;
83 mHighBw = 0;
84 mSourceSplit = false;
85 mSourceSplitAlways = false;
86 mRGBHasNoScalar = false;
87
88 updatePanelInfo();
89
90 if(!updateSysFsInfo()) {
91 ALOGE("Unable to read display sysfs node");
92 }
93 if (mMdpRev == MDP_V3_0_4){
94 mMDPVersion = MDP_V3_0_4;
95 }
96
97 mHasOverlay = false;
98 if((mMDPVersion >= MDP_V4_0) ||
99 (mMDPVersion == MDP_V_UNKNOWN) ||
100 (mMDPVersion == MDP_V3_0_4))
101 mHasOverlay = true;
102 if(!updateSplitInfo()) {
103 ALOGE("Unable to read display split node");
104 }
105 }
106
~MDPVersion()107 MDPVersion::~MDPVersion() {
108 close(mFd);
109 }
110
tokenizeParams(char * inputParams,const char * delim,char * tokenStr[],int * idx)111 int MDPVersion::tokenizeParams(char *inputParams, const char *delim,
112 char* tokenStr[], int *idx) {
113 char *tmp_token = NULL;
114 char *temp_ptr;
115 int index = 0;
116 if (!inputParams) {
117 return -1;
118 }
119 tmp_token = strtok_r(inputParams, delim, &temp_ptr);
120 while (tmp_token != NULL) {
121 tokenStr[index++] = tmp_token;
122 tmp_token = strtok_r(NULL, " ", &temp_ptr);
123 }
124 *idx = index;
125 return 0;
126 }
127 // This function reads the sysfs node to read the primary panel type
128 // and updates information accordingly
updatePanelInfo()129 void MDPVersion::updatePanelInfo() {
130 FILE *displayDeviceFP = NULL;
131 FILE *panelInfoNodeFP = NULL;
132 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
133 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
134 char panelInfo[MAX_FRAME_BUFFER_NAME_SIZE];
135 const char *strCmdPanel = "mipi dsi cmd panel";
136 const char *strVideoPanel = "mipi dsi video panel";
137 const char *strLVDSPanel = "lvds panel";
138 const char *strEDPPanel = "edp panel";
139
140 displayDeviceFP = fopen("/sys/class/graphics/fb0/msm_fb_type", "r");
141 if(displayDeviceFP){
142 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
143 displayDeviceFP);
144 if(strncmp(fbType, strCmdPanel, strlen(strCmdPanel)) == 0) {
145 mPanelInfo.mType = MIPI_CMD_PANEL;
146 }
147 else if(strncmp(fbType, strVideoPanel, strlen(strVideoPanel)) == 0) {
148 mPanelInfo.mType = MIPI_VIDEO_PANEL;
149 }
150 else if(strncmp(fbType, strLVDSPanel, strlen(strLVDSPanel)) == 0) {
151 mPanelInfo.mType = LVDS_PANEL;
152 }
153 else if(strncmp(fbType, strEDPPanel, strlen(strEDPPanel)) == 0) {
154 mPanelInfo.mType = EDP_PANEL;
155 }
156 fclose(displayDeviceFP);
157 } else {
158 ALOGE("Unable to read Primary Panel Information");
159 }
160
161 panelInfoNodeFP = fopen("/sys/class/graphics/fb0/msm_fb_panel_info", "r");
162 if(panelInfoNodeFP){
163 size_t len = PAGE_SIZE;
164 ssize_t read;
165 char *readLine = (char *) malloc (len);
166 while((read = getline((char **)&readLine, &len,
167 panelInfoNodeFP)) != -1) {
168 int token_ct=0;
169 char *tokens[10];
170 memset(tokens, 0, sizeof(tokens));
171
172 if(!tokenizeParams(readLine, TOKEN_PARAMS_DELIM, tokens,
173 &token_ct)) {
174 if(!strncmp(tokens[0], "pu_en", strlen("pu_en"))) {
175 mPanelInfo.mPartialUpdateEnable = atoi(tokens[1]);
176 ALOGI("PartialUpdate status: %s",
177 mPanelInfo.mPartialUpdateEnable? "Enabled" :
178 "Disabled");
179 }
180 if(!strncmp(tokens[0], "xstart", strlen("xstart"))) {
181 mPanelInfo.mLeftAlign = atoi(tokens[1]);
182 ALOGI("Left Align: %d", mPanelInfo.mLeftAlign);
183 }
184 if(!strncmp(tokens[0], "walign", strlen("walign"))) {
185 mPanelInfo.mWidthAlign = atoi(tokens[1]);
186 ALOGI("Width Align: %d", mPanelInfo.mWidthAlign);
187 }
188 if(!strncmp(tokens[0], "ystart", strlen("ystart"))) {
189 mPanelInfo.mTopAlign = atoi(tokens[1]);
190 ALOGI("Top Align: %d", mPanelInfo.mTopAlign);
191 }
192 if(!strncmp(tokens[0], "halign", strlen("halign"))) {
193 mPanelInfo.mHeightAlign = atoi(tokens[1]);
194 ALOGI("Height Align: %d", mPanelInfo.mHeightAlign);
195 }
196 if(!strncmp(tokens[0], "min_w", strlen("min_w"))) {
197 mPanelInfo.mMinROIWidth = atoi(tokens[1]);
198 ALOGI("Min ROI Width: %d", mPanelInfo.mMinROIWidth);
199 }
200 if(!strncmp(tokens[0], "min_h", strlen("min_h"))) {
201 mPanelInfo.mMinROIHeight = atoi(tokens[1]);
202 ALOGI("Min ROI Height: %d", mPanelInfo.mMinROIHeight);
203 }
204 if(!strncmp(tokens[0], "roi_merge", strlen("roi_merge"))) {
205 mPanelInfo.mNeedsROIMerge = atoi(tokens[1]);
206 ALOGI("Needs ROI Merge: %d", mPanelInfo.mNeedsROIMerge);
207 }
208 }
209 }
210 fclose(panelInfoNodeFP);
211 } else {
212 ALOGE("Failed to open msm_fb_panel_info node");
213 }
214 }
215
216 // This function reads the sysfs node to read MDP capabilities
217 // and parses and updates information accordingly.
updateSysFsInfo()218 bool MDPVersion::updateSysFsInfo() {
219 FILE *sysfsFd;
220 size_t len = PAGE_SIZE;
221 ssize_t read;
222 char *line = NULL;
223 char sysfsPath[255];
224 memset(sysfsPath, 0, sizeof(sysfsPath));
225 snprintf(sysfsPath , sizeof(sysfsPath),
226 "/sys/class/graphics/fb0/mdp/caps");
227 char property[PROPERTY_VALUE_MAX];
228 bool enableMacroTile = false;
229
230 if((property_get("persist.hwc.macro_tile_enable", property, NULL) > 0) &&
231 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
232 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
233 enableMacroTile = true;
234 }
235
236 sysfsFd = fopen(sysfsPath, "rb");
237
238 if (sysfsFd == NULL) {
239 ALOGE("%s: sysFsFile file '%s' not found",
240 __FUNCTION__, sysfsPath);
241 return false;
242 } else {
243 line = (char *) malloc(len);
244 while((read = getline(&line, &len, sysfsFd)) != -1) {
245 int index=0;
246 char *tokens[10];
247 memset(tokens, 0, sizeof(tokens));
248
249 // parse the line and update information accordingly
250 if(!tokenizeParams(line, TOKEN_PARAMS_DELIM, tokens, &index)) {
251 if(!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) {
252 mMdpRev = atoi(tokens[1]);
253 }
254 else if(!strncmp(tokens[0], "rgb_pipes", strlen("rgb_pipes"))) {
255 mRGBPipes = (uint8_t)atoi(tokens[1]);
256 }
257 else if(!strncmp(tokens[0], "vig_pipes", strlen("vig_pipes"))) {
258 mVGPipes = (uint8_t)atoi(tokens[1]);
259 }
260 else if(!strncmp(tokens[0], "dma_pipes", strlen("dma_pipes"))) {
261 mDMAPipes = (uint8_t)atoi(tokens[1]);
262 }
263 else if(!strncmp(tokens[0], "max_downscale_ratio",
264 strlen("max_downscale_ratio"))) {
265 mMDPDownscale = atoi(tokens[1]);
266 }
267 else if(!strncmp(tokens[0], "max_upscale_ratio",
268 strlen("max_upscale_ratio"))) {
269 mMDPUpscale = atoi(tokens[1]);
270 } else if(!strncmp(tokens[0], "max_bandwidth_low",
271 strlen("max_bandwidth_low"))) {
272 mLowBw = atol(tokens[1]);
273 } else if(!strncmp(tokens[0], "max_bandwidth_high",
274 strlen("max_bandwidth_high"))) {
275 mHighBw = atol(tokens[1]);
276 } else if(!strncmp(tokens[0], "features", strlen("features"))) {
277 for(int i=1; i<index;i++) {
278 if(!strncmp(tokens[i], "bwc", strlen("bwc"))) {
279 mFeatures |= MDP_BWC_EN;
280 }
281 else if(!strncmp(tokens[i], "decimation",
282 strlen("decimation"))) {
283 mFeatures |= MDP_DECIMATION_EN;
284 }
285 else if(!strncmp(tokens[i], "tile_format",
286 strlen("tile_format"))) {
287 if(enableMacroTile)
288 mMacroTileEnabled = true;
289 } else if(!strncmp(tokens[i], "src_split",
290 strlen("src_split"))) {
291 mSourceSplit = true;
292 }
293 else if(!strncmp(tokens[i], "non_scalar_rgb",
294 strlen("non_scalar_rgb"))) {
295 mRGBHasNoScalar = true;
296 }
297 }
298 }
299 }
300 }
301 free(line);
302 fclose(sysfsFd);
303 }
304
305 if(mSourceSplit) {
306 memset(sysfsPath, 0, sizeof(sysfsPath));
307 snprintf(sysfsPath , sizeof(sysfsPath),
308 "/sys/class/graphics/fb0/msm_fb_src_split_info");
309
310 sysfsFd = fopen(sysfsPath, "rb");
311 if (sysfsFd == NULL) {
312 ALOGE("%s: Opening file %s failed with error %s", __FUNCTION__,
313 sysfsPath, strerror(errno));
314 return false;
315 } else {
316 line = (char *) malloc(len);
317 if((read = getline(&line, &len, sysfsFd)) != -1) {
318 if(!strncmp(line, "src_split_always",
319 strlen("src_split_always"))) {
320 mSourceSplitAlways = true;
321 }
322 }
323 free(line);
324 fclose(sysfsFd);
325 }
326 }
327
328 ALOGD_IF(DEBUG, "%s: mMDPVersion: %d mMdpRev: %x mRGBPipes:%d,"
329 "mVGPipes:%d", __FUNCTION__, mMDPVersion, mMdpRev,
330 mRGBPipes, mVGPipes);
331 ALOGD_IF(DEBUG, "%s:mDMAPipes:%d \t mMDPDownscale:%d, mFeatures:%d",
332 __FUNCTION__, mDMAPipes, mMDPDownscale, mFeatures);
333 ALOGD_IF(DEBUG, "%s:mLowBw: %lu mHighBw: %lu", __FUNCTION__, mLowBw,
334 mHighBw);
335
336 return true;
337 }
338
339 // This function reads the sysfs node to read MDP capabilities
340 // and parses and updates information accordingly.
updateSplitInfo()341 bool MDPVersion::updateSplitInfo() {
342 if(mMDPVersion >= MDSS_V5) {
343 char split[64] = {0};
344 FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r");
345 if(fp){
346 //Format "left right" space as delimiter
347 if(fread(split, sizeof(char), 64, fp)) {
348 split[sizeof(split) - 1] = '\0';
349 mSplit.mLeft = atoi(split);
350 ALOGI_IF(mSplit.mLeft, "Left Split=%d", mSplit.mLeft);
351 char *rght = strpbrk(split, " ");
352 if(rght)
353 mSplit.mRight = atoi(rght + 1);
354 ALOGI_IF(mSplit.mRight, "Right Split=%d", mSplit.mRight);
355 }
356 } else {
357 ALOGE("Failed to open mdss_fb_split node");
358 return false;
359 }
360 if(fp)
361 fclose(fp);
362 }
363 return true;
364 }
365
366
hasMinCropWidthLimitation() const367 bool MDPVersion::hasMinCropWidthLimitation() const {
368 return mMdpRev <= MDSS_MDP_HW_REV_102;
369 }
370
supportsDecimation()371 bool MDPVersion::supportsDecimation() {
372 return mFeatures & MDP_DECIMATION_EN;
373 }
374
getMaxMDPDownscale()375 uint32_t MDPVersion::getMaxMDPDownscale() {
376 return mMDPDownscale;
377 }
378
getMaxMDPUpscale()379 uint32_t MDPVersion::getMaxMDPUpscale() {
380 return mMDPUpscale;
381 }
382
supportsBWC()383 bool MDPVersion::supportsBWC() {
384 // BWC - Bandwidth Compression
385 return (mFeatures & MDP_BWC_EN);
386 }
387
supportsMacroTile()388 bool MDPVersion::supportsMacroTile() {
389 // MACRO TILE support
390 return mMacroTileEnabled;
391 }
392
isSrcSplit() const393 bool MDPVersion::isSrcSplit() const {
394 return mSourceSplit;
395 }
396
isSrcSplitAlways() const397 bool MDPVersion::isSrcSplitAlways() const {
398 return mSourceSplitAlways;
399 }
400
isRGBScalarSupported() const401 bool MDPVersion::isRGBScalarSupported() const {
402 return (!mRGBHasNoScalar);
403 }
404
is8x26()405 bool MDPVersion::is8x26() {
406 return (mMdpRev >= MDSS_MDP_HW_REV_101 and
407 mMdpRev < MDSS_MDP_HW_REV_102);
408 }
409
is8x74v2()410 bool MDPVersion::is8x74v2() {
411 return (mMdpRev >= MDSS_MDP_HW_REV_102 and
412 mMdpRev < MDSS_MDP_HW_REV_103);
413 }
414
is8084()415 bool MDPVersion::is8084() {
416 return (mMdpRev >= MDSS_MDP_HW_REV_103 and
417 mMdpRev < MDSS_MDP_HW_REV_104);
418 }
419
is8092()420 bool MDPVersion::is8092() {
421 return (mMdpRev >= MDSS_MDP_HW_REV_200 and
422 mMdpRev < MDSS_MDP_HW_REV_206);
423 }
424
is8x16()425 bool MDPVersion::is8x16() {
426 return (mMdpRev >= MDSS_MDP_HW_REV_106 and
427 mMdpRev < MDSS_MDP_HW_REV_107);
428 }
429
430 }; //namespace qdutils
431
432