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> |
| 30 | #include <fcntl.h> |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 31 | #include <sys/ioctl.h> |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 32 | #include <linux/fb.h> |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 33 | #include <linux/msm_mdp.h> |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 34 | #include "mdp_version.h" |
| 35 | |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame^] | 36 | #define DEBUG 0 |
| 37 | |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 38 | ANDROID_SINGLETON_STATIC_INSTANCE(qdutils::MDPVersion); |
| 39 | namespace qdutils { |
| 40 | |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame^] | 41 | #define TOKEN_PARAMS_DELIM "=" |
| 42 | |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 43 | MDPVersion::MDPVersion() |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 44 | { |
| 45 | int fb_fd = open("/dev/graphics/fb0", O_RDWR); |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 46 | char panel_type = 0; |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 47 | struct fb_fix_screeninfo fb_finfo; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 48 | |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame^] | 49 | mMDPVersion = MDP_V_UNKNOWN; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 50 | mMdpRev = 0; |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 51 | mRGBPipes = 0; |
| 52 | mVGPipes = 0; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 53 | mDMAPipes = 0; |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 54 | mFeatures = 0; |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame^] | 55 | mMDPUpscale = 0; |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 56 | //TODO get this from driver, default for A-fam to 8 |
| 57 | mMDPDownscale = 8; |
Xiaoming Zhou | 3da712a | 2013-07-04 14:37:45 -0400 | [diff] [blame] | 58 | mFd = fb_fd; |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 59 | |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 60 | if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fb_finfo) < 0) { |
| 61 | ALOGE("FBIOGET_FSCREENINFO failed"); |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 62 | } else { |
| 63 | if(!strncmp(fb_finfo.id, "msmfb", 5)) { |
| 64 | char str_ver[4] = { 0 }; |
| 65 | memcpy(str_ver, &fb_finfo.id[5], 3); |
| 66 | str_ver[3] = '\0'; |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame^] | 67 | mMDPVersion = atoi(str_ver); |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 68 | //Normalize MDP version to ease comparison. |
| 69 | //This is needed only because |
| 70 | //MDP 3.0.3 reports value as 303 which |
| 71 | //is more than all the others |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame^] | 72 | if (mMDPVersion < 100) |
| 73 | mMDPVersion *= 10; |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 74 | |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 75 | mRGBPipes = mVGPipes = 2; |
| 76 | |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 77 | } else if (!strncmp(fb_finfo.id, "mdssfb", 6)) { |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame^] | 78 | mMDPVersion = MDSS_V5; |
| 79 | if(!updateSysFsInfo()) { |
| 80 | ALOGE("Unable to read updateSysFsInfo"); |
Sushil Chauhan | 07a2c76 | 2013-03-06 15:36:49 -0800 | [diff] [blame] | 81 | } |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame^] | 82 | if (mMdpRev == MDP_V3_0_4){ |
| 83 | mMDPVersion = MDP_V3_0_4; |
| 84 | } |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 85 | } |
Carl Vanderlip | 045d9c8 | 2013-05-09 16:22:32 -0700 | [diff] [blame] | 86 | |
| 87 | /* Assumes panel type is 2nd element in '_' delimited id string */ |
| 88 | char * ptype = strstr(fb_finfo.id, "_"); |
| 89 | if (!ptype || (*(++ptype) == '\0')) { |
| 90 | ALOGE("Invalid framebuffer info string: %s", fb_finfo.id); |
| 91 | ptype = fb_finfo.id; |
| 92 | } |
| 93 | panel_type = *ptype; |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 94 | } |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 95 | mPanelType = panel_type; |
Naseer Ahmed | 96c4c95 | 2012-07-25 18:27:14 -0700 | [diff] [blame] | 96 | mHasOverlay = false; |
Xiaoming Zhou | 530f861 | 2013-05-01 20:53:06 -0400 | [diff] [blame] | 97 | if((mMDPVersion >= MDP_V4_0) || |
| 98 | (mMDPVersion == MDP_V_UNKNOWN) || |
| 99 | (mMDPVersion == MDP_V3_0_4)) |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 100 | mHasOverlay = true; |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 101 | if(mMDPVersion >= MDSS_V5) { |
Sravan Kumar D.V.N | 2947259 | 2013-09-26 18:17:37 +0530 | [diff] [blame] | 102 | char split[64] = {0}; |
Saurabh Shah | 67a38c3 | 2013-06-10 16:23:15 -0700 | [diff] [blame] | 103 | FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r"); |
| 104 | if(fp){ |
| 105 | //Format "left right" space as delimiter |
| 106 | if(fread(split, sizeof(char), 64, fp)) { |
| 107 | mSplit.mLeft = atoi(split); |
| 108 | ALOGI_IF(mSplit.mLeft, "Left Split=%d", mSplit.mLeft); |
| 109 | char *rght = strpbrk(split, " "); |
| 110 | if(rght) |
| 111 | mSplit.mRight = atoi(rght + 1); |
| 112 | ALOGI_IF(rght, "Right Split=%d", mSplit.mRight); |
| 113 | } |
| 114 | } else { |
| 115 | ALOGE("Failed to open mdss_fb_split node"); |
| 116 | } |
| 117 | |
| 118 | if(fp) |
| 119 | fclose(fp); |
| 120 | } |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 121 | } |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 122 | |
Xiaoming Zhou | 3da712a | 2013-07-04 14:37:45 -0400 | [diff] [blame] | 123 | MDPVersion::~MDPVersion() { |
| 124 | close(mFd); |
| 125 | } |
| 126 | |
manoj kumar amara venkata mastan | bc05ef0 | 2013-09-17 19:29:32 -0700 | [diff] [blame^] | 127 | int MDPVersion::tokenizeParams(char *inputParams, const char *delim, |
| 128 | char* tokenStr[], int *idx) { |
| 129 | char *tmp_token = NULL; |
| 130 | char *temp_ptr; |
| 131 | int ret = 0, index = 0; |
| 132 | if (!inputParams) { |
| 133 | return -1; |
| 134 | } |
| 135 | tmp_token = strtok_r(inputParams, delim, &temp_ptr); |
| 136 | while (tmp_token != NULL) { |
| 137 | tokenStr[index++] = tmp_token; |
| 138 | tmp_token = strtok_r(NULL, " ", &temp_ptr); |
| 139 | } |
| 140 | *idx = index; |
| 141 | return 0; |
| 142 | } |
| 143 | |
| 144 | |
| 145 | // This function reads the sysfs node to read MDP capabilities |
| 146 | // and parses and updates information accordingly. |
| 147 | bool MDPVersion::updateSysFsInfo() { |
| 148 | FILE *sysfsFd; |
| 149 | size_t len = 0; |
| 150 | ssize_t read; |
| 151 | char *line = NULL; |
| 152 | char sysfsPath[255]; |
| 153 | memset(sysfsPath, 0, sizeof(sysfsPath)); |
| 154 | snprintf(sysfsPath , sizeof(sysfsPath), |
| 155 | "/sys/class/graphics/fb0/mdp/caps"); |
| 156 | |
| 157 | sysfsFd = fopen(sysfsPath, "rb"); |
| 158 | |
| 159 | if (sysfsFd == NULL) { |
| 160 | ALOGE("%s: sysFsFile file '%s' not found", |
| 161 | __FUNCTION__, sysfsPath); |
| 162 | return false; |
| 163 | } else { |
| 164 | while((read = getline(&line, &len, sysfsFd)) != -1) { |
| 165 | int index=0; |
| 166 | char *tokens[10]; |
| 167 | memset(tokens, 0, sizeof(tokens)); |
| 168 | |
| 169 | // parse the line and update information accordingly |
| 170 | if(!tokenizeParams(line, TOKEN_PARAMS_DELIM, tokens, &index)) { |
| 171 | if(!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) { |
| 172 | mMdpRev = atoi(tokens[1]); |
| 173 | } |
| 174 | else if(!strncmp(tokens[0], "rgb_pipes", strlen("rgb_pipes"))) { |
| 175 | mRGBPipes = atoi(tokens[1]); |
| 176 | } |
| 177 | else if(!strncmp(tokens[0], "vig_pipes", strlen("vig_pipes"))) { |
| 178 | mVGPipes = atoi(tokens[1]); |
| 179 | } |
| 180 | else if(!strncmp(tokens[0], "dma_pipes", strlen("dma_pipes"))) { |
| 181 | mDMAPipes = atoi(tokens[1]); |
| 182 | } |
| 183 | else if(!strncmp(tokens[0], "max_downscale_ratio", |
| 184 | strlen("max_downscale_ratio"))) { |
| 185 | mMDPDownscale = atoi(tokens[1]); |
| 186 | } |
| 187 | else if(!strncmp(tokens[0], "max_upscale_ratio", |
| 188 | strlen("max_upscale_ratio"))) { |
| 189 | mMDPUpscale = atoi(tokens[1]); |
| 190 | } |
| 191 | else if(!strncmp(tokens[0], "features", strlen("features"))) { |
| 192 | for(int i=1; i<index;i++) { |
| 193 | if(!strncmp(tokens[i], "bwc", strlen("bwc"))) { |
| 194 | mFeatures |= MDP_BWC_EN; |
| 195 | } |
| 196 | else if(!strncmp(tokens[i], "decimation", |
| 197 | strlen("decimation"))) { |
| 198 | mFeatures |= MDP_DECIMATION_EN; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | free(line); |
| 204 | line = NULL; |
| 205 | } |
| 206 | fclose(sysfsFd); |
| 207 | } |
| 208 | ALOGD_IF(DEBUG, "%s: mMDPVersion: %d mMdpRev: %x mRGBPipes:%d," |
| 209 | "mVGPipes:%d", __FUNCTION__, mMDPVersion, mMdpRev, |
| 210 | mRGBPipes, mVGPipes); |
| 211 | ALOGD_IF(DEBUG, "%s:mDMAPipes:%d \t mMDPDownscale:%d, mFeatures:%d", |
| 212 | __FUNCTION__, mDMAPipes, mMDPDownscale, mFeatures); |
| 213 | return true; |
| 214 | } |
| 215 | |
Saurabh Shah | bd2d083 | 2013-04-04 14:33:08 -0700 | [diff] [blame] | 216 | bool MDPVersion::supportsDecimation() { |
| 217 | return mFeatures & MDP_DECIMATION_EN; |
| 218 | } |
| 219 | |
| 220 | uint32_t MDPVersion::getMaxMDPDownscale() { |
| 221 | return mMDPDownscale; |
| 222 | } |
| 223 | |
Sushil Chauhan | bab187a | 2013-01-30 17:44:15 -0800 | [diff] [blame] | 224 | bool MDPVersion::supportsBWC() { |
| 225 | // BWC - Bandwidth Compression |
| 226 | return (mFeatures & MDP_BWC_EN); |
| 227 | } |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 228 | |
| 229 | bool MDPVersion::is8x26() { |
Amara Venkata Mastan Manoj Kumar | 5fa4d60 | 2013-06-30 16:24:22 -0700 | [diff] [blame] | 230 | // check for 8x26 variants |
| 231 | // chip variants have same major number and minor numbers usually vary |
| 232 | // for e.g., MDSS_MDP_HW_REV_101 is 0x10010000 |
| 233 | // 1001 - major number |
| 234 | // 0000 - minor number |
| 235 | // 8x26 v1 minor number is 0000 |
| 236 | // v2 minor number is 0001 etc.. |
| 237 | if( mMdpRev >= MDSS_MDP_HW_REV_101 && mMdpRev < MDSS_MDP_HW_REV_102) { |
| 238 | return true; |
| 239 | } |
| 240 | return false; |
Saurabh Shah | e247408 | 2013-05-15 16:32:13 -0700 | [diff] [blame] | 241 | } |
| 242 | |
Saurabh Shah | 75b81b9 | 2013-08-29 17:31:17 -0700 | [diff] [blame] | 243 | bool MDPVersion::is8x74v2() { |
| 244 | if( mMdpRev >= MDSS_MDP_HW_REV_102 && mMdpRev < MDSS_MDP_HW_REV_103) { |
| 245 | return true; |
| 246 | } |
| 247 | return false; |
| 248 | } |
| 249 | |
Naseer Ahmed | a87da60 | 2012-07-01 23:54:19 -0700 | [diff] [blame] | 250 | }; //namespace qdutils |
| 251 | |