blob: 9ee2d8df9819de30e27db9e8ce33e8f5697a75b3 [file] [log] [blame]
Naseer Ahmeda87da602012-07-01 23:54:19 -07001/*
Arun Kumar K.Rf15adc02014-01-21 21:26:25 -08002 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
Naseer Ahmeda87da602012-07-01 23:54:19 -07003
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.
Duy Truong73d36df2013-02-09 20:33:23 -080013 * * Neither the name of The Linux Foundation nor the names of its
Naseer Ahmeda87da602012-07-01 23:54:19 -070014 * 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>
Sushil Chauhan07a2c762013-03-06 15:36:49 -080030#include <linux/msm_mdp.h>
Naseer Ahmeda87da602012-07-01 23:54:19 -070031#include "mdp_version.h"
32
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070033#define DEBUG 0
34
Naseer Ahmeda87da602012-07-01 23:54:19 -070035ANDROID_SINGLETON_STATIC_INSTANCE(qdutils::MDPVersion);
36namespace qdutils {
37
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070038#define TOKEN_PARAMS_DELIM "="
39
Saurabh Shahd3877632014-01-07 09:29:03 -080040#ifndef MDSS_MDP_REV
41enum mdp_rev {
42 MDSS_MDP_HW_REV_100 = 0x10000000, //8974 v1
43 MDSS_MDP_HW_REV_101 = 0x10010000, //8x26
44 MDSS_MDP_HW_REV_102 = 0x10020000, //8974 v2
45 MDSS_MDP_HW_REV_103 = 0x10030000, //8084
46 MDSS_MDP_HW_REV_104 = 0x10040000, //Next version
47 MDSS_MDP_HW_REV_105 = 0x10050000, //Next version
radhakrishna2e792f92014-03-13 11:39:33 +053048 MDSS_MDP_HW_REV_106 = 0x10060000, //8x16
Saurabh Shahd3877632014-01-07 09:29:03 -080049 MDSS_MDP_HW_REV_200 = 0x20000000, //8092
50 MDSS_MDP_HW_REV_206 = 0x20060000, //Future
51};
52#else
53enum mdp_rev {
54 MDSS_MDP_HW_REV_104 = 0x10040000, //Next version
55 MDSS_MDP_HW_REV_206 = 0x20060000, //Future
radhakrishna2e792f92014-03-13 11:39:33 +053056 MDSS_MDP_HW_REV_107 = 0x10070000, //Next version
Saurabh Shahd3877632014-01-07 09:29:03 -080057};
58#endif
59
Naseer Ahmed96c4c952012-07-25 18:27:14 -070060MDPVersion::MDPVersion()
Naseer Ahmeda87da602012-07-01 23:54:19 -070061{
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080062 mMDPVersion = MDSS_V5;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080063 mMdpRev = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070064 mRGBPipes = 0;
65 mVGPipes = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080066 mDMAPipes = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070067 mFeatures = 0;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070068 mMDPUpscale = 0;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080069 mMDPDownscale = 0;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070070 mMacroTileEnabled = false;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080071 mPanelType = NO_PANEL;
Saurabh Shah8ee5e892013-11-25 10:51:40 -080072 mLowBw = 0;
73 mHighBw = 0;
Saurabh Shahab47c692014-02-12 18:45:57 -080074 mSourceSplit = false;
radhakrishna2e792f92014-03-13 11:39:33 +053075 mRGBHasNoScalar = false;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080076
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080077 if(!updatePanelInfo()) {
78 ALOGE("Unable to read Primary Panel Information");
Naseer Ahmeda87da602012-07-01 23:54:19 -070079 }
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080080 if(!updateSysFsInfo()) {
81 ALOGE("Unable to read display sysfs node");
82 }
83 if (mMdpRev == MDP_V3_0_4){
84 mMDPVersion = MDP_V3_0_4;
85 }
86
Naseer Ahmed96c4c952012-07-25 18:27:14 -070087 mHasOverlay = false;
Xiaoming Zhou530f8612013-05-01 20:53:06 -040088 if((mMDPVersion >= MDP_V4_0) ||
89 (mMDPVersion == MDP_V_UNKNOWN) ||
90 (mMDPVersion == MDP_V3_0_4))
Naseer Ahmeda87da602012-07-01 23:54:19 -070091 mHasOverlay = true;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080092 if(!updateSplitInfo()) {
93 ALOGE("Unable to read display split node");
Saurabh Shah67a38c32013-06-10 16:23:15 -070094 }
Naseer Ahmeda87da602012-07-01 23:54:19 -070095}
Saurabh Shahbd2d0832013-04-04 14:33:08 -070096
Xiaoming Zhou3da712a2013-07-04 14:37:45 -040097MDPVersion::~MDPVersion() {
98 close(mFd);
99}
100
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700101int MDPVersion::tokenizeParams(char *inputParams, const char *delim,
102 char* tokenStr[], int *idx) {
103 char *tmp_token = NULL;
104 char *temp_ptr;
Arun Kumar K.Rf15adc02014-01-21 21:26:25 -0800105 int index = 0;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700106 if (!inputParams) {
107 return -1;
108 }
109 tmp_token = strtok_r(inputParams, delim, &temp_ptr);
110 while (tmp_token != NULL) {
111 tokenStr[index++] = tmp_token;
112 tmp_token = strtok_r(NULL, " ", &temp_ptr);
113 }
114 *idx = index;
115 return 0;
116}
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800117// This function reads the sysfs node to read the primary panel type
118// and updates information accordingly
119bool MDPVersion::updatePanelInfo() {
120 FILE *displayDeviceFP = NULL;
121 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
122 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
123 const char *strCmdPanel = "mipi dsi cmd panel";
124 const char *strVideoPanel = "mipi dsi video panel";
125 const char *strLVDSPanel = "lvds panel";
126 const char *strEDPPanel = "edp panel";
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700127
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800128 displayDeviceFP = fopen("/sys/class/graphics/fb0/msm_fb_type", "r");
129 if(displayDeviceFP){
130 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
131 displayDeviceFP);
132 if(strncmp(fbType, strCmdPanel, strlen(strCmdPanel)) == 0) {
133 mPanelType = MIPI_CMD_PANEL;
134 }
135 else if(strncmp(fbType, strVideoPanel, strlen(strVideoPanel)) == 0) {
136 mPanelType = MIPI_VIDEO_PANEL;
137 }
138 else if(strncmp(fbType, strLVDSPanel, strlen(strLVDSPanel)) == 0) {
139 mPanelType = LVDS_PANEL;
140 }
141 else if(strncmp(fbType, strEDPPanel, strlen(strEDPPanel)) == 0) {
142 mPanelType = EDP_PANEL;
143 }
144 fclose(displayDeviceFP);
145 return true;
146 }else {
147 return false;
148 }
149}
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700150
151// This function reads the sysfs node to read MDP capabilities
152// and parses and updates information accordingly.
153bool MDPVersion::updateSysFsInfo() {
154 FILE *sysfsFd;
Sushil Chauhanac184602014-02-14 11:49:47 -0800155 size_t len = PAGE_SIZE;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700156 ssize_t read;
157 char *line = NULL;
158 char sysfsPath[255];
159 memset(sysfsPath, 0, sizeof(sysfsPath));
160 snprintf(sysfsPath , sizeof(sysfsPath),
161 "/sys/class/graphics/fb0/mdp/caps");
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700162 char property[PROPERTY_VALUE_MAX];
163 bool enableMacroTile = false;
164
165 if((property_get("persist.hwc.macro_tile_enable", property, NULL) > 0) &&
166 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
167 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
168 enableMacroTile = true;
169 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700170
171 sysfsFd = fopen(sysfsPath, "rb");
172
173 if (sysfsFd == NULL) {
174 ALOGE("%s: sysFsFile file '%s' not found",
175 __FUNCTION__, sysfsPath);
176 return false;
177 } else {
Sushil Chauhanac184602014-02-14 11:49:47 -0800178 line = (char *) malloc(len);
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700179 while((read = getline(&line, &len, sysfsFd)) != -1) {
180 int index=0;
181 char *tokens[10];
182 memset(tokens, 0, sizeof(tokens));
183
184 // parse the line and update information accordingly
185 if(!tokenizeParams(line, TOKEN_PARAMS_DELIM, tokens, &index)) {
186 if(!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) {
187 mMdpRev = atoi(tokens[1]);
188 }
189 else if(!strncmp(tokens[0], "rgb_pipes", strlen("rgb_pipes"))) {
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530190 mRGBPipes = (uint8_t)atoi(tokens[1]);
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700191 }
192 else if(!strncmp(tokens[0], "vig_pipes", strlen("vig_pipes"))) {
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530193 mVGPipes = (uint8_t)atoi(tokens[1]);
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700194 }
195 else if(!strncmp(tokens[0], "dma_pipes", strlen("dma_pipes"))) {
Dileep Kumar Reddibf333c72014-02-25 14:32:51 +0530196 mDMAPipes = (uint8_t)atoi(tokens[1]);
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700197 }
198 else if(!strncmp(tokens[0], "max_downscale_ratio",
199 strlen("max_downscale_ratio"))) {
200 mMDPDownscale = atoi(tokens[1]);
201 }
202 else if(!strncmp(tokens[0], "max_upscale_ratio",
203 strlen("max_upscale_ratio"))) {
204 mMDPUpscale = atoi(tokens[1]);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800205 } else if(!strncmp(tokens[0], "max_bandwidth_low",
206 strlen("max_bandwidth_low"))) {
207 mLowBw = atol(tokens[1]);
208 } else if(!strncmp(tokens[0], "max_bandwidth_high",
209 strlen("max_bandwidth_high"))) {
210 mHighBw = atol(tokens[1]);
211 } else if(!strncmp(tokens[0], "features", strlen("features"))) {
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700212 for(int i=1; i<index;i++) {
213 if(!strncmp(tokens[i], "bwc", strlen("bwc"))) {
214 mFeatures |= MDP_BWC_EN;
215 }
216 else if(!strncmp(tokens[i], "decimation",
217 strlen("decimation"))) {
218 mFeatures |= MDP_DECIMATION_EN;
219 }
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700220 else if(!strncmp(tokens[i], "tile_format",
221 strlen("tile_format"))) {
222 if(enableMacroTile)
223 mMacroTileEnabled = true;
Saurabh Shahab47c692014-02-12 18:45:57 -0800224 } else if(!strncmp(tokens[i], "src_split",
225 strlen("src_split"))) {
226 mSourceSplit = true;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700227 }
radhakrishna2e792f92014-03-13 11:39:33 +0530228 else if(!strncmp(tokens[i], "non_scalar_rgb",
229 strlen("non_scalar_rgb"))) {
230 mRGBHasNoScalar = true;
231 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700232 }
233 }
234 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700235 }
Sushil Chauhanac184602014-02-14 11:49:47 -0800236 free(line);
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700237 fclose(sysfsFd);
238 }
239 ALOGD_IF(DEBUG, "%s: mMDPVersion: %d mMdpRev: %x mRGBPipes:%d,"
240 "mVGPipes:%d", __FUNCTION__, mMDPVersion, mMdpRev,
241 mRGBPipes, mVGPipes);
242 ALOGD_IF(DEBUG, "%s:mDMAPipes:%d \t mMDPDownscale:%d, mFeatures:%d",
243 __FUNCTION__, mDMAPipes, mMDPDownscale, mFeatures);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800244 ALOGD_IF(DEBUG, "%s:mLowBw: %lu mHighBw: %lu", __FUNCTION__, mLowBw,
245 mHighBw);
246
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700247 return true;
248}
249
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800250// This function reads the sysfs node to read MDP capabilities
251// and parses and updates information accordingly.
252bool MDPVersion::updateSplitInfo() {
253 if(mMDPVersion >= MDSS_V5) {
254 char split[64] = {0};
255 FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r");
256 if(fp){
257 //Format "left right" space as delimiter
258 if(fread(split, sizeof(char), 64, fp)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800259 split[sizeof(split) - 1] = '\0';
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800260 mSplit.mLeft = atoi(split);
261 ALOGI_IF(mSplit.mLeft, "Left Split=%d", mSplit.mLeft);
262 char *rght = strpbrk(split, " ");
263 if(rght)
264 mSplit.mRight = atoi(rght + 1);
265 ALOGI_IF(mSplit.mRight, "Right Split=%d", mSplit.mRight);
266 }
267 } else {
268 ALOGE("Failed to open mdss_fb_split node");
269 return false;
270 }
271 if(fp)
272 fclose(fp);
273 }
274 return true;
275}
276
277
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700278bool MDPVersion::supportsDecimation() {
279 return mFeatures & MDP_DECIMATION_EN;
280}
281
282uint32_t MDPVersion::getMaxMDPDownscale() {
283 return mMDPDownscale;
284}
285
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800286uint32_t MDPVersion::getMaxMDPUpscale() {
287 return mMDPUpscale;
288}
289
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800290bool MDPVersion::supportsBWC() {
291 // BWC - Bandwidth Compression
292 return (mFeatures & MDP_BWC_EN);
293}
Saurabh Shahe2474082013-05-15 16:32:13 -0700294
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700295bool MDPVersion::supportsMacroTile() {
296 // MACRO TILE support
297 return mMacroTileEnabled;
298}
299
Saurabh Shahab47c692014-02-12 18:45:57 -0800300bool MDPVersion::isSrcSplit() const {
301 return mSourceSplit;
302}
303
radhakrishna2e792f92014-03-13 11:39:33 +0530304bool MDPVersion::isRGBScalarSupported() const {
305 return (!mRGBHasNoScalar);
306}
307
Saurabh Shahd3877632014-01-07 09:29:03 -0800308bool MDPVersion::is8x26() {
309 return (mMdpRev >= MDSS_MDP_HW_REV_101 and
310 mMdpRev < MDSS_MDP_HW_REV_102);
311}
312
313bool MDPVersion::is8x74v2() {
314 return (mMdpRev >= MDSS_MDP_HW_REV_102 and
315 mMdpRev < MDSS_MDP_HW_REV_103);
316}
317
318bool MDPVersion::is8084() {
319 return (mMdpRev >= MDSS_MDP_HW_REV_103 and
320 mMdpRev < MDSS_MDP_HW_REV_104);
321}
322
323bool MDPVersion::is8092() {
324 return (mMdpRev >= MDSS_MDP_HW_REV_200 and
325 mMdpRev < MDSS_MDP_HW_REV_206);
326}
327
radhakrishna2e792f92014-03-13 11:39:33 +0530328bool MDPVersion::is8x16() {
329 return (mMdpRev >= MDSS_MDP_HW_REV_106 and
330 mMdpRev < MDSS_MDP_HW_REV_107);
331}
332
Naseer Ahmeda87da602012-07-01 23:54:19 -0700333}; //namespace qdutils
334