blob: e43468e21ab4462a7cd335efe456a4d74d477f8b [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
48 MDSS_MDP_HW_REV_107 = 0x10070000, //Next version
49 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
56};
57#endif
58
Naseer Ahmed96c4c952012-07-25 18:27:14 -070059MDPVersion::MDPVersion()
Naseer Ahmeda87da602012-07-01 23:54:19 -070060{
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080061 mMDPVersion = MDSS_V5;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080062 mMdpRev = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070063 mRGBPipes = 0;
64 mVGPipes = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080065 mDMAPipes = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070066 mFeatures = 0;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070067 mMDPUpscale = 0;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080068 mMDPDownscale = 0;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070069 mMacroTileEnabled = false;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080070 mPanelType = NO_PANEL;
Saurabh Shah8ee5e892013-11-25 10:51:40 -080071 mLowBw = 0;
72 mHighBw = 0;
Saurabh Shahab47c692014-02-12 18:45:57 -080073 mSourceSplit = false;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080074
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080075 if(!updatePanelInfo()) {
76 ALOGE("Unable to read Primary Panel Information");
Naseer Ahmeda87da602012-07-01 23:54:19 -070077 }
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080078 if(!updateSysFsInfo()) {
79 ALOGE("Unable to read display sysfs node");
80 }
81 if (mMdpRev == MDP_V3_0_4){
82 mMDPVersion = MDP_V3_0_4;
83 }
84
Naseer Ahmed96c4c952012-07-25 18:27:14 -070085 mHasOverlay = false;
Xiaoming Zhou530f8612013-05-01 20:53:06 -040086 if((mMDPVersion >= MDP_V4_0) ||
87 (mMDPVersion == MDP_V_UNKNOWN) ||
88 (mMDPVersion == MDP_V3_0_4))
Naseer Ahmeda87da602012-07-01 23:54:19 -070089 mHasOverlay = true;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080090 if(!updateSplitInfo()) {
91 ALOGE("Unable to read display split node");
Saurabh Shah67a38c32013-06-10 16:23:15 -070092 }
Naseer Ahmeda87da602012-07-01 23:54:19 -070093}
Saurabh Shahbd2d0832013-04-04 14:33:08 -070094
Xiaoming Zhou3da712a2013-07-04 14:37:45 -040095MDPVersion::~MDPVersion() {
96 close(mFd);
97}
98
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070099int MDPVersion::tokenizeParams(char *inputParams, const char *delim,
100 char* tokenStr[], int *idx) {
101 char *tmp_token = NULL;
102 char *temp_ptr;
Arun Kumar K.Rf15adc02014-01-21 21:26:25 -0800103 int index = 0;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700104 if (!inputParams) {
105 return -1;
106 }
107 tmp_token = strtok_r(inputParams, delim, &temp_ptr);
108 while (tmp_token != NULL) {
109 tokenStr[index++] = tmp_token;
110 tmp_token = strtok_r(NULL, " ", &temp_ptr);
111 }
112 *idx = index;
113 return 0;
114}
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800115// This function reads the sysfs node to read the primary panel type
116// and updates information accordingly
117bool MDPVersion::updatePanelInfo() {
118 FILE *displayDeviceFP = NULL;
119 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
120 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
121 const char *strCmdPanel = "mipi dsi cmd panel";
122 const char *strVideoPanel = "mipi dsi video panel";
123 const char *strLVDSPanel = "lvds panel";
124 const char *strEDPPanel = "edp panel";
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700125
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800126 displayDeviceFP = fopen("/sys/class/graphics/fb0/msm_fb_type", "r");
127 if(displayDeviceFP){
128 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
129 displayDeviceFP);
130 if(strncmp(fbType, strCmdPanel, strlen(strCmdPanel)) == 0) {
131 mPanelType = MIPI_CMD_PANEL;
132 }
133 else if(strncmp(fbType, strVideoPanel, strlen(strVideoPanel)) == 0) {
134 mPanelType = MIPI_VIDEO_PANEL;
135 }
136 else if(strncmp(fbType, strLVDSPanel, strlen(strLVDSPanel)) == 0) {
137 mPanelType = LVDS_PANEL;
138 }
139 else if(strncmp(fbType, strEDPPanel, strlen(strEDPPanel)) == 0) {
140 mPanelType = EDP_PANEL;
141 }
142 fclose(displayDeviceFP);
143 return true;
144 }else {
145 return false;
146 }
147}
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700148
149// This function reads the sysfs node to read MDP capabilities
150// and parses and updates information accordingly.
151bool MDPVersion::updateSysFsInfo() {
152 FILE *sysfsFd;
Sushil Chauhanac184602014-02-14 11:49:47 -0800153 size_t len = PAGE_SIZE;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700154 ssize_t read;
155 char *line = NULL;
156 char sysfsPath[255];
157 memset(sysfsPath, 0, sizeof(sysfsPath));
158 snprintf(sysfsPath , sizeof(sysfsPath),
159 "/sys/class/graphics/fb0/mdp/caps");
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700160 char property[PROPERTY_VALUE_MAX];
161 bool enableMacroTile = false;
162
163 if((property_get("persist.hwc.macro_tile_enable", property, NULL) > 0) &&
164 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
165 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
166 enableMacroTile = true;
167 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700168
169 sysfsFd = fopen(sysfsPath, "rb");
170
171 if (sysfsFd == NULL) {
172 ALOGE("%s: sysFsFile file '%s' not found",
173 __FUNCTION__, sysfsPath);
174 return false;
175 } else {
Sushil Chauhanac184602014-02-14 11:49:47 -0800176 line = (char *) malloc(len);
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700177 while((read = getline(&line, &len, sysfsFd)) != -1) {
178 int index=0;
179 char *tokens[10];
180 memset(tokens, 0, sizeof(tokens));
181
182 // parse the line and update information accordingly
183 if(!tokenizeParams(line, TOKEN_PARAMS_DELIM, tokens, &index)) {
184 if(!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) {
185 mMdpRev = atoi(tokens[1]);
186 }
187 else if(!strncmp(tokens[0], "rgb_pipes", strlen("rgb_pipes"))) {
188 mRGBPipes = atoi(tokens[1]);
189 }
190 else if(!strncmp(tokens[0], "vig_pipes", strlen("vig_pipes"))) {
191 mVGPipes = atoi(tokens[1]);
192 }
193 else if(!strncmp(tokens[0], "dma_pipes", strlen("dma_pipes"))) {
194 mDMAPipes = atoi(tokens[1]);
195 }
196 else if(!strncmp(tokens[0], "max_downscale_ratio",
197 strlen("max_downscale_ratio"))) {
198 mMDPDownscale = atoi(tokens[1]);
199 }
200 else if(!strncmp(tokens[0], "max_upscale_ratio",
201 strlen("max_upscale_ratio"))) {
202 mMDPUpscale = atoi(tokens[1]);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800203 } else if(!strncmp(tokens[0], "max_bandwidth_low",
204 strlen("max_bandwidth_low"))) {
205 mLowBw = atol(tokens[1]);
206 } else if(!strncmp(tokens[0], "max_bandwidth_high",
207 strlen("max_bandwidth_high"))) {
208 mHighBw = atol(tokens[1]);
209 } else if(!strncmp(tokens[0], "features", strlen("features"))) {
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700210 for(int i=1; i<index;i++) {
211 if(!strncmp(tokens[i], "bwc", strlen("bwc"))) {
212 mFeatures |= MDP_BWC_EN;
213 }
214 else if(!strncmp(tokens[i], "decimation",
215 strlen("decimation"))) {
216 mFeatures |= MDP_DECIMATION_EN;
217 }
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700218 else if(!strncmp(tokens[i], "tile_format",
219 strlen("tile_format"))) {
220 if(enableMacroTile)
221 mMacroTileEnabled = true;
Saurabh Shahab47c692014-02-12 18:45:57 -0800222 } else if(!strncmp(tokens[i], "src_split",
223 strlen("src_split"))) {
224 mSourceSplit = true;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700225 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700226 }
227 }
228 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700229 }
Sushil Chauhanac184602014-02-14 11:49:47 -0800230 free(line);
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700231 fclose(sysfsFd);
232 }
233 ALOGD_IF(DEBUG, "%s: mMDPVersion: %d mMdpRev: %x mRGBPipes:%d,"
234 "mVGPipes:%d", __FUNCTION__, mMDPVersion, mMdpRev,
235 mRGBPipes, mVGPipes);
236 ALOGD_IF(DEBUG, "%s:mDMAPipes:%d \t mMDPDownscale:%d, mFeatures:%d",
237 __FUNCTION__, mDMAPipes, mMDPDownscale, mFeatures);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800238 ALOGD_IF(DEBUG, "%s:mLowBw: %lu mHighBw: %lu", __FUNCTION__, mLowBw,
239 mHighBw);
240
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700241 return true;
242}
243
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800244// This function reads the sysfs node to read MDP capabilities
245// and parses and updates information accordingly.
246bool MDPVersion::updateSplitInfo() {
247 if(mMDPVersion >= MDSS_V5) {
248 char split[64] = {0};
249 FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r");
250 if(fp){
251 //Format "left right" space as delimiter
252 if(fread(split, sizeof(char), 64, fp)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800253 split[sizeof(split) - 1] = '\0';
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800254 mSplit.mLeft = atoi(split);
255 ALOGI_IF(mSplit.mLeft, "Left Split=%d", mSplit.mLeft);
256 char *rght = strpbrk(split, " ");
257 if(rght)
258 mSplit.mRight = atoi(rght + 1);
259 ALOGI_IF(mSplit.mRight, "Right Split=%d", mSplit.mRight);
260 }
261 } else {
262 ALOGE("Failed to open mdss_fb_split node");
263 return false;
264 }
265 if(fp)
266 fclose(fp);
267 }
268 return true;
269}
270
271
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700272bool MDPVersion::supportsDecimation() {
273 return mFeatures & MDP_DECIMATION_EN;
274}
275
276uint32_t MDPVersion::getMaxMDPDownscale() {
277 return mMDPDownscale;
278}
279
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800280uint32_t MDPVersion::getMaxMDPUpscale() {
281 return mMDPUpscale;
282}
283
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800284bool MDPVersion::supportsBWC() {
285 // BWC - Bandwidth Compression
286 return (mFeatures & MDP_BWC_EN);
287}
Saurabh Shahe2474082013-05-15 16:32:13 -0700288
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700289bool MDPVersion::supportsMacroTile() {
290 // MACRO TILE support
291 return mMacroTileEnabled;
292}
293
Saurabh Shahab47c692014-02-12 18:45:57 -0800294bool MDPVersion::isSrcSplit() const {
295 return mSourceSplit;
296}
297
Saurabh Shahd3877632014-01-07 09:29:03 -0800298bool MDPVersion::is8x26() {
299 return (mMdpRev >= MDSS_MDP_HW_REV_101 and
300 mMdpRev < MDSS_MDP_HW_REV_102);
301}
302
303bool MDPVersion::is8x74v2() {
304 return (mMdpRev >= MDSS_MDP_HW_REV_102 and
305 mMdpRev < MDSS_MDP_HW_REV_103);
306}
307
308bool MDPVersion::is8084() {
309 return (mMdpRev >= MDSS_MDP_HW_REV_103 and
310 mMdpRev < MDSS_MDP_HW_REV_104);
311}
312
313bool MDPVersion::is8092() {
314 return (mMdpRev >= MDSS_MDP_HW_REV_200 and
315 mMdpRev < MDSS_MDP_HW_REV_206);
316}
317
Naseer Ahmeda87da602012-07-01 23:54:19 -0700318}; //namespace qdutils
319