Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 1 | /* |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 2 | * Copyright (c) 2012-2013, The Linux Foundation. All rights reserved. |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 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. |
Duy Truong | 73d36df | 2013-02-09 20:33:23 -0800 | [diff] [blame] | 13 | * * Neither the name of The Linux Foundation nor the names of its |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 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> |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 30 | #include <linux/msm_mdp.h> |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 31 | #include "mdp_version.h" |
| 32 | |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame] | 33 | #define DEBUG 0 |
| 34 | |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 35 | ANDROID_SINGLETON_STATIC_INSTANCE(qdutils::MDPVersion); |
| 36 | namespace qdutils { |
| 37 | |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame] | 38 | #define TOKEN_PARAMS_DELIM "=" |
| 39 | |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 40 | MDPVersion::MDPVersion() |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 41 | { |
Manoj Kumar AVM | c65ec61 | 2013-11-21 09:20:29 -0800 | [diff] [blame] | 42 | mMDPVersion = MDSS_V5; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 43 | mMdpRev = 0; |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 44 | mRGBPipes = 0; |
| 45 | mVGPipes = 0; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 46 | mDMAPipes = 0; |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 47 | mFeatures = 0; |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame] | 48 | mMDPUpscale = 0; |
Manoj Kumar AVM | c65ec61 | 2013-11-21 09:20:29 -0800 | [diff] [blame] | 49 | mMDPDownscale = 0; |
| 50 | mPanelType = NO_PANEL; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 51 | |
Manoj Kumar AVM | c65ec61 | 2013-11-21 09:20:29 -0800 | [diff] [blame] | 52 | if(!updatePanelInfo()) { |
| 53 | ALOGE("Unable to read Primary Panel Information"); |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 54 | } |
Manoj Kumar AVM | c65ec61 | 2013-11-21 09:20:29 -0800 | [diff] [blame] | 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 | |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 62 | mHasOverlay = false; |
Xiaoming Zhou | 530f861 | 2013-05-01 20:53:06 -0400 | [diff] [blame] | 63 | if((mMDPVersion >= MDP_V4_0) || |
| 64 | (mMDPVersion == MDP_V_UNKNOWN) || |
| 65 | (mMDPVersion == MDP_V3_0_4)) |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 66 | mHasOverlay = true; |
Manoj Kumar AVM | c65ec61 | 2013-11-21 09:20:29 -0800 | [diff] [blame] | 67 | if(!updateSplitInfo()) { |
| 68 | ALOGE("Unable to read display split node"); |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 69 | } |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 70 | } |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 71 | |
Xiaoming Zhou | 3da712a | 2013-07-04 14:37:45 -0400 | [diff] [blame] | 72 | MDPVersion::~MDPVersion() { |
| 73 | close(mFd); |
| 74 | } |
| 75 | |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame] | 76 | int 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 | } |
Manoj Kumar AVM | c65ec61 | 2013-11-21 09:20:29 -0800 | [diff] [blame] | 92 | // This function reads the sysfs node to read the primary panel type |
| 93 | // and updates information accordingly |
| 94 | bool 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"; |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame] | 102 | |
Manoj Kumar AVM | c65ec61 | 2013-11-21 09:20:29 -0800 | [diff] [blame] | 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 | } |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame] | 125 | |
| 126 | // This function reads the sysfs node to read MDP capabilities |
| 127 | // and parses and updates information accordingly. |
| 128 | bool 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 | |
Manoj Kumar AVM | c65ec61 | 2013-11-21 09:20:29 -0800 | [diff] [blame] | 197 | // This function reads the sysfs node to read MDP capabilities |
| 198 | // and parses and updates information accordingly. |
| 199 | bool 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 | |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 224 | bool MDPVersion::supportsDecimation() { |
| 225 | return mFeatures & MDP_DECIMATION_EN; |
| 226 | } |
| 227 | |
| 228 | uint32_t MDPVersion::getMaxMDPDownscale() { |
| 229 | return mMDPDownscale; |
| 230 | } |
| 231 | |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 232 | bool MDPVersion::supportsBWC() { |
| 233 | // BWC - Bandwidth Compression |
| 234 | return (mFeatures & MDP_BWC_EN); |
| 235 | } |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 236 | |
| 237 | bool MDPVersion::is8x26() { |
Amara Venkata Mastan Manoj Kumar | 5fa4d60 | 2013-06-30 16:24:22 -0700 | [diff] [blame] | 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; |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 249 | } |
| 250 | |
Saurabh Shah | 75b81b9 | 2013-08-29 17:31:17 -0700 | [diff] [blame] | 251 | bool MDPVersion::is8x74v2() { |
Zohaib Alam | 4eff790 | 2013-11-01 02:35:05 -0400 | [diff] [blame] | 252 | if( mMdpRev >= MDSS_MDP_HW_REV_102 && mMdpRev < MDSS_MDP_HW_REV_200) { |
Saurabh Shah | 75b81b9 | 2013-08-29 17:31:17 -0700 | [diff] [blame] | 253 | return true; |
| 254 | } |
| 255 | return false; |
| 256 | } |
| 257 | |
Zohaib Alam | 4eff790 | 2013-11-01 02:35:05 -0400 | [diff] [blame] | 258 | bool MDPVersion::is8x92() { |
| 259 | if( mMdpRev >= MDSS_MDP_HW_REV_200 && mMdpRev < MDSS_MDP_HW_REV_206) { |
| 260 | return true; |
| 261 | } |
| 262 | return false; |
| 263 | } |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 264 | }; //namespace qdutils |
| 265 | |