mdp_version.cpp revision 1b66878aec2d36dbc5aa9f8109885448431af236
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 mPanelType = NO_PANEL; 51 52 if(!updatePanelInfo()) { 53 ALOGE("Unable to read Primary Panel Information"); 54 } 55 if(!updateSysFsInfo()) { 56 ALOGE("Unable to read display sysfs node"); 57 } 58 if (mMdpRev == MDP_V3_0_4){ 59 mMDPVersion = MDP_V3_0_4; 60 } 61 62 mHasOverlay = false; 63 if((mMDPVersion >= MDP_V4_0) || 64 (mMDPVersion == MDP_V_UNKNOWN) || 65 (mMDPVersion == MDP_V3_0_4)) 66 mHasOverlay = true; 67 if(!updateSplitInfo()) { 68 ALOGE("Unable to read display split node"); 69 } 70} 71 72MDPVersion::~MDPVersion() { 73 close(mFd); 74} 75 76int MDPVersion::tokenizeParams(char *inputParams, const char *delim, 77 char* tokenStr[], int *idx) { 78 char *tmp_token = NULL; 79 char *temp_ptr; 80 int ret = 0, index = 0; 81 if (!inputParams) { 82 return -1; 83 } 84 tmp_token = strtok_r(inputParams, delim, &temp_ptr); 85 while (tmp_token != NULL) { 86 tokenStr[index++] = tmp_token; 87 tmp_token = strtok_r(NULL, " ", &temp_ptr); 88 } 89 *idx = index; 90 return 0; 91} 92// This function reads the sysfs node to read the primary panel type 93// and updates information accordingly 94bool MDPVersion::updatePanelInfo() { 95 FILE *displayDeviceFP = NULL; 96 const int MAX_FRAME_BUFFER_NAME_SIZE = 128; 97 char fbType[MAX_FRAME_BUFFER_NAME_SIZE]; 98 const char *strCmdPanel = "mipi dsi cmd panel"; 99 const char *strVideoPanel = "mipi dsi video panel"; 100 const char *strLVDSPanel = "lvds panel"; 101 const char *strEDPPanel = "edp panel"; 102 103 displayDeviceFP = fopen("/sys/class/graphics/fb0/msm_fb_type", "r"); 104 if(displayDeviceFP){ 105 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE, 106 displayDeviceFP); 107 if(strncmp(fbType, strCmdPanel, strlen(strCmdPanel)) == 0) { 108 mPanelType = MIPI_CMD_PANEL; 109 } 110 else if(strncmp(fbType, strVideoPanel, strlen(strVideoPanel)) == 0) { 111 mPanelType = MIPI_VIDEO_PANEL; 112 } 113 else if(strncmp(fbType, strLVDSPanel, strlen(strLVDSPanel)) == 0) { 114 mPanelType = LVDS_PANEL; 115 } 116 else if(strncmp(fbType, strEDPPanel, strlen(strEDPPanel)) == 0) { 117 mPanelType = EDP_PANEL; 118 } 119 fclose(displayDeviceFP); 120 return true; 121 }else { 122 return false; 123 } 124} 125 126// This function reads the sysfs node to read MDP capabilities 127// and parses and updates information accordingly. 128bool MDPVersion::updateSysFsInfo() { 129 FILE *sysfsFd; 130 size_t len = 0; 131 ssize_t read; 132 char *line = NULL; 133 char sysfsPath[255]; 134 memset(sysfsPath, 0, sizeof(sysfsPath)); 135 snprintf(sysfsPath , sizeof(sysfsPath), 136 "/sys/class/graphics/fb0/mdp/caps"); 137 138 sysfsFd = fopen(sysfsPath, "rb"); 139 140 if (sysfsFd == NULL) { 141 ALOGE("%s: sysFsFile file '%s' not found", 142 __FUNCTION__, sysfsPath); 143 return false; 144 } else { 145 while((read = getline(&line, &len, sysfsFd)) != -1) { 146 int index=0; 147 char *tokens[10]; 148 memset(tokens, 0, sizeof(tokens)); 149 150 // parse the line and update information accordingly 151 if(!tokenizeParams(line, TOKEN_PARAMS_DELIM, tokens, &index)) { 152 if(!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) { 153 mMdpRev = atoi(tokens[1]); 154 } 155 else if(!strncmp(tokens[0], "rgb_pipes", strlen("rgb_pipes"))) { 156 mRGBPipes = atoi(tokens[1]); 157 } 158 else if(!strncmp(tokens[0], "vig_pipes", strlen("vig_pipes"))) { 159 mVGPipes = atoi(tokens[1]); 160 } 161 else if(!strncmp(tokens[0], "dma_pipes", strlen("dma_pipes"))) { 162 mDMAPipes = atoi(tokens[1]); 163 } 164 else if(!strncmp(tokens[0], "max_downscale_ratio", 165 strlen("max_downscale_ratio"))) { 166 mMDPDownscale = atoi(tokens[1]); 167 } 168 else if(!strncmp(tokens[0], "max_upscale_ratio", 169 strlen("max_upscale_ratio"))) { 170 mMDPUpscale = atoi(tokens[1]); 171 } 172 else if(!strncmp(tokens[0], "features", strlen("features"))) { 173 for(int i=1; i<index;i++) { 174 if(!strncmp(tokens[i], "bwc", strlen("bwc"))) { 175 mFeatures |= MDP_BWC_EN; 176 } 177 else if(!strncmp(tokens[i], "decimation", 178 strlen("decimation"))) { 179 mFeatures |= MDP_DECIMATION_EN; 180 } 181 } 182 } 183 } 184 free(line); 185 line = NULL; 186 } 187 fclose(sysfsFd); 188 } 189 ALOGD_IF(DEBUG, "%s: mMDPVersion: %d mMdpRev: %x mRGBPipes:%d," 190 "mVGPipes:%d", __FUNCTION__, mMDPVersion, mMdpRev, 191 mRGBPipes, mVGPipes); 192 ALOGD_IF(DEBUG, "%s:mDMAPipes:%d \t mMDPDownscale:%d, mFeatures:%d", 193 __FUNCTION__, mDMAPipes, mMDPDownscale, mFeatures); 194 return true; 195} 196 197// This function reads the sysfs node to read MDP capabilities 198// and parses and updates information accordingly. 199bool MDPVersion::updateSplitInfo() { 200 if(mMDPVersion >= MDSS_V5) { 201 char split[64] = {0}; 202 FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r"); 203 if(fp){ 204 //Format "left right" space as delimiter 205 if(fread(split, sizeof(char), 64, fp)) { 206 mSplit.mLeft = atoi(split); 207 ALOGI_IF(mSplit.mLeft, "Left Split=%d", mSplit.mLeft); 208 char *rght = strpbrk(split, " "); 209 if(rght) 210 mSplit.mRight = atoi(rght + 1); 211 ALOGI_IF(mSplit.mRight, "Right Split=%d", mSplit.mRight); 212 } 213 } else { 214 ALOGE("Failed to open mdss_fb_split node"); 215 return false; 216 } 217 if(fp) 218 fclose(fp); 219 } 220 return true; 221} 222 223 224bool MDPVersion::supportsDecimation() { 225 return mFeatures & MDP_DECIMATION_EN; 226} 227 228uint32_t MDPVersion::getMaxMDPDownscale() { 229 return mMDPDownscale; 230} 231 232bool MDPVersion::supportsBWC() { 233 // BWC - Bandwidth Compression 234 return (mFeatures & MDP_BWC_EN); 235} 236 237bool MDPVersion::is8x26() { 238 // check for 8x26 variants 239 // chip variants have same major number and minor numbers usually vary 240 // for e.g., MDSS_MDP_HW_REV_101 is 0x10010000 241 // 1001 - major number 242 // 0000 - minor number 243 // 8x26 v1 minor number is 0000 244 // v2 minor number is 0001 etc.. 245 if( mMdpRev >= MDSS_MDP_HW_REV_101 && mMdpRev < MDSS_MDP_HW_REV_102) { 246 return true; 247 } 248 return false; 249} 250 251bool MDPVersion::is8x74v2() { 252 if( mMdpRev >= MDSS_MDP_HW_REV_102 && mMdpRev < MDSS_MDP_HW_REV_200) { 253 return true; 254 } 255 return false; 256} 257 258bool MDPVersion::is8x92() { 259 if( mMdpRev >= MDSS_MDP_HW_REV_200 && mMdpRev < MDSS_MDP_HW_REV_206) { 260 return true; 261 } 262 return false; 263} 264}; //namespace qdutils 265 266