blob: 525010d347075fad62528683cd4d4cad6066020f [file] [log] [blame]
Naseer Ahmeda87da602012-07-01 23:54:19 -07001/*
Sushil Chauhan07a2c762013-03-06 15:36:49 -08002 * Copyright (c) 2012-2013, 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
Naseer Ahmed96c4c952012-07-25 18:27:14 -070040MDPVersion::MDPVersion()
Naseer Ahmeda87da602012-07-01 23:54:19 -070041{
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080042 mMDPVersion = MDSS_V5;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080043 mMdpRev = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070044 mRGBPipes = 0;
45 mVGPipes = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080046 mDMAPipes = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070047 mFeatures = 0;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070048 mMDPUpscale = 0;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080049 mMDPDownscale = 0;
Manoj Kumar AVM8a220812013-10-10 11:46:06 -070050 mMacroTileEnabled = false;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080051 mPanelType = NO_PANEL;
Saurabh Shah8ee5e892013-11-25 10:51:40 -080052 mLowBw = 0;
53 mHighBw = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080054
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080055 if(!updatePanelInfo()) {
56 ALOGE("Unable to read Primary Panel Information");
Naseer Ahmeda87da602012-07-01 23:54:19 -070057 }
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080058 if(!updateSysFsInfo()) {
59 ALOGE("Unable to read display sysfs node");
60 }
61 if (mMdpRev == MDP_V3_0_4){
62 mMDPVersion = MDP_V3_0_4;
63 }
64
Naseer Ahmed96c4c952012-07-25 18:27:14 -070065 mHasOverlay = false;
Xiaoming Zhou530f8612013-05-01 20:53:06 -040066 if((mMDPVersion >= MDP_V4_0) ||
67 (mMDPVersion == MDP_V_UNKNOWN) ||
68 (mMDPVersion == MDP_V3_0_4))
Naseer Ahmeda87da602012-07-01 23:54:19 -070069 mHasOverlay = true;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080070 if(!updateSplitInfo()) {
71 ALOGE("Unable to read display split node");
Saurabh Shah67a38c32013-06-10 16:23:15 -070072 }
Naseer Ahmeda87da602012-07-01 23:54:19 -070073}
Saurabh Shahbd2d0832013-04-04 14:33:08 -070074
Xiaoming Zhou3da712a2013-07-04 14:37:45 -040075MDPVersion::~MDPVersion() {
76 close(mFd);
77}
78
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070079int MDPVersion::tokenizeParams(char *inputParams, const char *delim,
80 char* tokenStr[], int *idx) {
81 char *tmp_token = NULL;
82 char *temp_ptr;
83 int ret = 0, index = 0;
84 if (!inputParams) {
85 return -1;
86 }
87 tmp_token = strtok_r(inputParams, delim, &temp_ptr);
88 while (tmp_token != NULL) {
89 tokenStr[index++] = tmp_token;
90 tmp_token = strtok_r(NULL, " ", &temp_ptr);
91 }
92 *idx = index;
93 return 0;
94}
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080095// This function reads the sysfs node to read the primary panel type
96// and updates information accordingly
97bool MDPVersion::updatePanelInfo() {
98 FILE *displayDeviceFP = NULL;
99 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
100 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
101 const char *strCmdPanel = "mipi dsi cmd panel";
102 const char *strVideoPanel = "mipi dsi video panel";
103 const char *strLVDSPanel = "lvds panel";
104 const char *strEDPPanel = "edp panel";
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700105
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800106 displayDeviceFP = fopen("/sys/class/graphics/fb0/msm_fb_type", "r");
107 if(displayDeviceFP){
108 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
109 displayDeviceFP);
110 if(strncmp(fbType, strCmdPanel, strlen(strCmdPanel)) == 0) {
111 mPanelType = MIPI_CMD_PANEL;
112 }
113 else if(strncmp(fbType, strVideoPanel, strlen(strVideoPanel)) == 0) {
114 mPanelType = MIPI_VIDEO_PANEL;
115 }
116 else if(strncmp(fbType, strLVDSPanel, strlen(strLVDSPanel)) == 0) {
117 mPanelType = LVDS_PANEL;
118 }
119 else if(strncmp(fbType, strEDPPanel, strlen(strEDPPanel)) == 0) {
120 mPanelType = EDP_PANEL;
121 }
122 fclose(displayDeviceFP);
123 return true;
124 }else {
125 return false;
126 }
127}
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700128
129// This function reads the sysfs node to read MDP capabilities
130// and parses and updates information accordingly.
131bool MDPVersion::updateSysFsInfo() {
132 FILE *sysfsFd;
133 size_t len = 0;
134 ssize_t read;
135 char *line = NULL;
136 char sysfsPath[255];
137 memset(sysfsPath, 0, sizeof(sysfsPath));
138 snprintf(sysfsPath , sizeof(sysfsPath),
139 "/sys/class/graphics/fb0/mdp/caps");
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700140 char property[PROPERTY_VALUE_MAX];
141 bool enableMacroTile = false;
142
143 if((property_get("persist.hwc.macro_tile_enable", property, NULL) > 0) &&
144 (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
145 (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
146 enableMacroTile = true;
147 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700148
149 sysfsFd = fopen(sysfsPath, "rb");
150
151 if (sysfsFd == NULL) {
152 ALOGE("%s: sysFsFile file '%s' not found",
153 __FUNCTION__, sysfsPath);
154 return false;
155 } else {
156 while((read = getline(&line, &len, sysfsFd)) != -1) {
157 int index=0;
158 char *tokens[10];
159 memset(tokens, 0, sizeof(tokens));
160
161 // parse the line and update information accordingly
162 if(!tokenizeParams(line, TOKEN_PARAMS_DELIM, tokens, &index)) {
163 if(!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) {
164 mMdpRev = atoi(tokens[1]);
165 }
166 else if(!strncmp(tokens[0], "rgb_pipes", strlen("rgb_pipes"))) {
167 mRGBPipes = atoi(tokens[1]);
168 }
169 else if(!strncmp(tokens[0], "vig_pipes", strlen("vig_pipes"))) {
170 mVGPipes = atoi(tokens[1]);
171 }
172 else if(!strncmp(tokens[0], "dma_pipes", strlen("dma_pipes"))) {
173 mDMAPipes = atoi(tokens[1]);
174 }
175 else if(!strncmp(tokens[0], "max_downscale_ratio",
176 strlen("max_downscale_ratio"))) {
177 mMDPDownscale = atoi(tokens[1]);
178 }
179 else if(!strncmp(tokens[0], "max_upscale_ratio",
180 strlen("max_upscale_ratio"))) {
181 mMDPUpscale = atoi(tokens[1]);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800182 } else if(!strncmp(tokens[0], "max_bandwidth_low",
183 strlen("max_bandwidth_low"))) {
184 mLowBw = atol(tokens[1]);
185 } else if(!strncmp(tokens[0], "max_bandwidth_high",
186 strlen("max_bandwidth_high"))) {
187 mHighBw = atol(tokens[1]);
188 } else if(!strncmp(tokens[0], "features", strlen("features"))) {
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700189 for(int i=1; i<index;i++) {
190 if(!strncmp(tokens[i], "bwc", strlen("bwc"))) {
191 mFeatures |= MDP_BWC_EN;
192 }
193 else if(!strncmp(tokens[i], "decimation",
194 strlen("decimation"))) {
195 mFeatures |= MDP_DECIMATION_EN;
196 }
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700197 else if(!strncmp(tokens[i], "tile_format",
198 strlen("tile_format"))) {
199 if(enableMacroTile)
200 mMacroTileEnabled = true;
201 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700202 }
203 }
204 }
205 free(line);
206 line = NULL;
207 }
208 fclose(sysfsFd);
209 }
210 ALOGD_IF(DEBUG, "%s: mMDPVersion: %d mMdpRev: %x mRGBPipes:%d,"
211 "mVGPipes:%d", __FUNCTION__, mMDPVersion, mMdpRev,
212 mRGBPipes, mVGPipes);
213 ALOGD_IF(DEBUG, "%s:mDMAPipes:%d \t mMDPDownscale:%d, mFeatures:%d",
214 __FUNCTION__, mDMAPipes, mMDPDownscale, mFeatures);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800215 ALOGD_IF(DEBUG, "%s:mLowBw: %lu mHighBw: %lu", __FUNCTION__, mLowBw,
216 mHighBw);
217
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700218 return true;
219}
220
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800221// This function reads the sysfs node to read MDP capabilities
222// and parses and updates information accordingly.
223bool MDPVersion::updateSplitInfo() {
224 if(mMDPVersion >= MDSS_V5) {
225 char split[64] = {0};
226 FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r");
227 if(fp){
228 //Format "left right" space as delimiter
229 if(fread(split, sizeof(char), 64, fp)) {
230 mSplit.mLeft = atoi(split);
231 ALOGI_IF(mSplit.mLeft, "Left Split=%d", mSplit.mLeft);
232 char *rght = strpbrk(split, " ");
233 if(rght)
234 mSplit.mRight = atoi(rght + 1);
235 ALOGI_IF(mSplit.mRight, "Right Split=%d", mSplit.mRight);
236 }
237 } else {
238 ALOGE("Failed to open mdss_fb_split node");
239 return false;
240 }
241 if(fp)
242 fclose(fp);
243 }
244 return true;
245}
246
247
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700248bool MDPVersion::supportsDecimation() {
249 return mFeatures & MDP_DECIMATION_EN;
250}
251
252uint32_t MDPVersion::getMaxMDPDownscale() {
253 return mMDPDownscale;
254}
255
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800256bool MDPVersion::supportsBWC() {
257 // BWC - Bandwidth Compression
258 return (mFeatures & MDP_BWC_EN);
259}
Saurabh Shahe2474082013-05-15 16:32:13 -0700260
Manoj Kumar AVM8a220812013-10-10 11:46:06 -0700261bool MDPVersion::supportsMacroTile() {
262 // MACRO TILE support
263 return mMacroTileEnabled;
264}
265
Naseer Ahmeda87da602012-07-01 23:54:19 -0700266}; //namespace qdutils
267