blob: 31c9155541389a3ffe95ff85fe76a34e058be927 [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;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080073
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080074 if(!updatePanelInfo()) {
75 ALOGE("Unable to read Primary Panel Information");
Naseer Ahmeda87da602012-07-01 23:54:19 -070076 }
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080077 if(!updateSysFsInfo()) {
78 ALOGE("Unable to read display sysfs node");
79 }
80 if (mMdpRev == MDP_V3_0_4){
81 mMDPVersion = MDP_V3_0_4;
82 }
83
Naseer Ahmed96c4c952012-07-25 18:27:14 -070084 mHasOverlay = false;
Xiaoming Zhou530f8612013-05-01 20:53:06 -040085 if((mMDPVersion >= MDP_V4_0) ||
86 (mMDPVersion == MDP_V_UNKNOWN) ||
87 (mMDPVersion == MDP_V3_0_4))
Naseer Ahmeda87da602012-07-01 23:54:19 -070088 mHasOverlay = true;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080089 if(!updateSplitInfo()) {
90 ALOGE("Unable to read display split node");
Saurabh Shah67a38c32013-06-10 16:23:15 -070091 }
Naseer Ahmeda87da602012-07-01 23:54:19 -070092}
Saurabh Shahbd2d0832013-04-04 14:33:08 -070093
Xiaoming Zhou3da712a2013-07-04 14:37:45 -040094MDPVersion::~MDPVersion() {
95 close(mFd);
96}
97
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070098int MDPVersion::tokenizeParams(char *inputParams, const char *delim,
99 char* tokenStr[], int *idx) {
100 char *tmp_token = NULL;
101 char *temp_ptr;
Arun Kumar K.Rf15adc02014-01-21 21:26:25 -0800102 int index = 0;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700103 if (!inputParams) {
104 return -1;
105 }
106 tmp_token = strtok_r(inputParams, delim, &temp_ptr);
107 while (tmp_token != NULL) {
108 tokenStr[index++] = tmp_token;
109 tmp_token = strtok_r(NULL, " ", &temp_ptr);
110 }
111 *idx = index;
112 return 0;
113}
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800114// This function reads the sysfs node to read the primary panel type
115// and updates information accordingly
116bool MDPVersion::updatePanelInfo() {
117 FILE *displayDeviceFP = NULL;
118 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
119 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
120 const char *strCmdPanel = "mipi dsi cmd panel";
121 const char *strVideoPanel = "mipi dsi video panel";
122 const char *strLVDSPanel = "lvds panel";
123 const char *strEDPPanel = "edp panel";
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700124
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800125 displayDeviceFP = fopen("/sys/class/graphics/fb0/msm_fb_type", "r");
126 if(displayDeviceFP){
127 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
128 displayDeviceFP);
129 if(strncmp(fbType, strCmdPanel, strlen(strCmdPanel)) == 0) {
130 mPanelType = MIPI_CMD_PANEL;
131 }
132 else if(strncmp(fbType, strVideoPanel, strlen(strVideoPanel)) == 0) {
133 mPanelType = MIPI_VIDEO_PANEL;
134 }
135 else if(strncmp(fbType, strLVDSPanel, strlen(strLVDSPanel)) == 0) {
136 mPanelType = LVDS_PANEL;
137 }
138 else if(strncmp(fbType, strEDPPanel, strlen(strEDPPanel)) == 0) {
139 mPanelType = EDP_PANEL;
140 }
141 fclose(displayDeviceFP);
142 return true;
143 }else {
144 return false;
145 }
146}
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700147
148// This function reads the sysfs node to read MDP capabilities
149// and parses and updates information accordingly.
150bool MDPVersion::updateSysFsInfo() {
151 FILE *sysfsFd;
152 size_t len = 0;
153 ssize_t read;
154 char *line = NULL;
155 char sysfsPath[255];
156 memset(sysfsPath, 0, sizeof(sysfsPath));
157 snprintf(sysfsPath , sizeof(sysfsPath),
158 "/sys/class/graphics/fb0/mdp/caps");
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700159 char property[PROPERTY_VALUE_MAX];
160 bool enableMacroTile = false;
161
162 if((property_get("persist.hwc.macro_tile_enable", property, NULL) > 0) &&
163 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
164 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
165 enableMacroTile = true;
166 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700167
168 sysfsFd = fopen(sysfsPath, "rb");
169
170 if (sysfsFd == NULL) {
171 ALOGE("%s: sysFsFile file '%s' not found",
172 __FUNCTION__, sysfsPath);
173 return false;
174 } else {
175 while((read = getline(&line, &len, sysfsFd)) != -1) {
176 int index=0;
177 char *tokens[10];
178 memset(tokens, 0, sizeof(tokens));
179
180 // parse the line and update information accordingly
181 if(!tokenizeParams(line, TOKEN_PARAMS_DELIM, tokens, &index)) {
182 if(!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) {
183 mMdpRev = atoi(tokens[1]);
184 }
185 else if(!strncmp(tokens[0], "rgb_pipes", strlen("rgb_pipes"))) {
186 mRGBPipes = atoi(tokens[1]);
187 }
188 else if(!strncmp(tokens[0], "vig_pipes", strlen("vig_pipes"))) {
189 mVGPipes = atoi(tokens[1]);
190 }
191 else if(!strncmp(tokens[0], "dma_pipes", strlen("dma_pipes"))) {
192 mDMAPipes = atoi(tokens[1]);
193 }
194 else if(!strncmp(tokens[0], "max_downscale_ratio",
195 strlen("max_downscale_ratio"))) {
196 mMDPDownscale = atoi(tokens[1]);
197 }
198 else if(!strncmp(tokens[0], "max_upscale_ratio",
199 strlen("max_upscale_ratio"))) {
200 mMDPUpscale = atoi(tokens[1]);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800201 } else if(!strncmp(tokens[0], "max_bandwidth_low",
202 strlen("max_bandwidth_low"))) {
203 mLowBw = atol(tokens[1]);
204 } else if(!strncmp(tokens[0], "max_bandwidth_high",
205 strlen("max_bandwidth_high"))) {
206 mHighBw = atol(tokens[1]);
207 } else if(!strncmp(tokens[0], "features", strlen("features"))) {
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700208 for(int i=1; i<index;i++) {
209 if(!strncmp(tokens[i], "bwc", strlen("bwc"))) {
210 mFeatures |= MDP_BWC_EN;
211 }
212 else if(!strncmp(tokens[i], "decimation",
213 strlen("decimation"))) {
214 mFeatures |= MDP_DECIMATION_EN;
215 }
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700216 else if(!strncmp(tokens[i], "tile_format",
217 strlen("tile_format"))) {
218 if(enableMacroTile)
219 mMacroTileEnabled = true;
220 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700221 }
222 }
223 }
224 free(line);
225 line = NULL;
226 }
227 fclose(sysfsFd);
228 }
229 ALOGD_IF(DEBUG, "%s: mMDPVersion: %d mMdpRev: %x mRGBPipes:%d,"
230 "mVGPipes:%d", __FUNCTION__, mMDPVersion, mMdpRev,
231 mRGBPipes, mVGPipes);
232 ALOGD_IF(DEBUG, "%s:mDMAPipes:%d \t mMDPDownscale:%d, mFeatures:%d",
233 __FUNCTION__, mDMAPipes, mMDPDownscale, mFeatures);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800234 ALOGD_IF(DEBUG, "%s:mLowBw: %lu mHighBw: %lu", __FUNCTION__, mLowBw,
235 mHighBw);
236
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700237 return true;
238}
239
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800240// This function reads the sysfs node to read MDP capabilities
241// and parses and updates information accordingly.
242bool MDPVersion::updateSplitInfo() {
243 if(mMDPVersion >= MDSS_V5) {
244 char split[64] = {0};
245 FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r");
246 if(fp){
247 //Format "left right" space as delimiter
248 if(fread(split, sizeof(char), 64, fp)) {
Ramkumar Radhakrishnan36bd5272014-01-31 20:03:01 -0800249 split[sizeof(split) - 1] = '\0';
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800250 mSplit.mLeft = atoi(split);
251 ALOGI_IF(mSplit.mLeft, "Left Split=%d", mSplit.mLeft);
252 char *rght = strpbrk(split, " ");
253 if(rght)
254 mSplit.mRight = atoi(rght + 1);
255 ALOGI_IF(mSplit.mRight, "Right Split=%d", mSplit.mRight);
256 }
257 } else {
258 ALOGE("Failed to open mdss_fb_split node");
259 return false;
260 }
261 if(fp)
262 fclose(fp);
263 }
264 return true;
265}
266
267
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700268bool MDPVersion::supportsDecimation() {
269 return mFeatures & MDP_DECIMATION_EN;
270}
271
272uint32_t MDPVersion::getMaxMDPDownscale() {
273 return mMDPDownscale;
274}
275
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800276uint32_t MDPVersion::getMaxMDPUpscale() {
277 return mMDPUpscale;
278}
279
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800280bool MDPVersion::supportsBWC() {
281 // BWC - Bandwidth Compression
282 return (mFeatures & MDP_BWC_EN);
283}
Saurabh Shahe2474082013-05-15 16:32:13 -0700284
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700285bool MDPVersion::supportsMacroTile() {
286 // MACRO TILE support
287 return mMacroTileEnabled;
288}
289
Saurabh Shahd3877632014-01-07 09:29:03 -0800290bool MDPVersion::is8x26() {
291 return (mMdpRev >= MDSS_MDP_HW_REV_101 and
292 mMdpRev < MDSS_MDP_HW_REV_102);
293}
294
295bool MDPVersion::is8x74v2() {
296 return (mMdpRev >= MDSS_MDP_HW_REV_102 and
297 mMdpRev < MDSS_MDP_HW_REV_103);
298}
299
300bool MDPVersion::is8084() {
301 return (mMdpRev >= MDSS_MDP_HW_REV_103 and
302 mMdpRev < MDSS_MDP_HW_REV_104);
303}
304
305bool MDPVersion::is8092() {
306 return (mMdpRev >= MDSS_MDP_HW_REV_200 and
307 mMdpRev < MDSS_MDP_HW_REV_206);
308}
309
Naseer Ahmeda87da602012-07-01 23:54:19 -0700310}; //namespace qdutils
311