mdp_version.cpp revision c38cdae859e0ee12ad3284a308eaeef9d2708c74
1/* 2 * Copyright (c) 2012-2013, 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 35ANDROID_SINGLETON_STATIC_INSTANCE(qdutils::MDPVersion); 36namespace qdutils { 37 38#define TOKEN_PARAMS_DELIM "=" 39 40MDPVersion::MDPVersion() 41{ 42 mMDPVersion = MDSS_V5; 43 mMdpRev = 0; 44 mRGBPipes = 0; 45 mVGPipes = 0; 46 mDMAPipes = 0; 47 mFeatures = 0; 48 mMDPUpscale = 0; 49 mMDPDownscale = 0; 50 mMacroTileEnabled = false; 51 mPanelType = NO_PANEL; 52 mLowBw = 0; 53 mHighBw = 0; 54 55 if(!updatePanelInfo()) { 56 ALOGE("Unable to read Primary Panel Information"); 57 } 58 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 65 mHasOverlay = false; 66 if((mMDPVersion >= MDP_V4_0) || 67 (mMDPVersion == MDP_V_UNKNOWN) || 68 (mMDPVersion == MDP_V3_0_4)) 69 mHasOverlay = true; 70 if(!updateSplitInfo()) { 71 ALOGE("Unable to read display split node"); 72 } 73} 74 75MDPVersion::~MDPVersion() { 76 close(mFd); 77} 78 79int 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} 95// 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"; 105 106 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} 128 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"); 140 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 } 148 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]); 182 } 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"))) { 189 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 } 197 else if(!strncmp(tokens[i], "tile_format", 198 strlen("tile_format"))) { 199 if(enableMacroTile) 200 mMacroTileEnabled = true; 201 } 202 } 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); 215 ALOGD_IF(DEBUG, "%s:mLowBw: %lu mHighBw: %lu", __FUNCTION__, mLowBw, 216 mHighBw); 217 218 return true; 219} 220 221// 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 248bool MDPVersion::supportsDecimation() { 249 return mFeatures & MDP_DECIMATION_EN; 250} 251 252uint32_t MDPVersion::getMaxMDPDownscale() { 253 return mMDPDownscale; 254} 255 256bool MDPVersion::supportsBWC() { 257 // BWC - Bandwidth Compression 258 return (mFeatures & MDP_BWC_EN); 259} 260 261bool MDPVersion::supportsMacroTile() { 262 // MACRO TILE support 263 return mMacroTileEnabled; 264} 265 266}; //namespace qdutils 267 268