blob: 185080176169c0bbf04403c26b5d04f1f6443cf6 [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>
30#include <fcntl.h>
Sushil Chauhan07a2c762013-03-06 15:36:49 -080031#include <sys/ioctl.h>
Naseer Ahmeda87da602012-07-01 23:54:19 -070032#include <linux/fb.h>
Sushil Chauhan07a2c762013-03-06 15:36:49 -080033#include <linux/msm_mdp.h>
Naseer Ahmeda87da602012-07-01 23:54:19 -070034#include "mdp_version.h"
35
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070036#define DEBUG 0
37
Naseer Ahmeda87da602012-07-01 23:54:19 -070038ANDROID_SINGLETON_STATIC_INSTANCE(qdutils::MDPVersion);
39namespace qdutils {
40
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070041#define TOKEN_PARAMS_DELIM "="
42
Naseer Ahmed96c4c952012-07-25 18:27:14 -070043MDPVersion::MDPVersion()
Naseer Ahmeda87da602012-07-01 23:54:19 -070044{
45 int fb_fd = open("/dev/graphics/fb0", O_RDWR);
Naseer Ahmed96c4c952012-07-25 18:27:14 -070046 char panel_type = 0;
Naseer Ahmeda87da602012-07-01 23:54:19 -070047 struct fb_fix_screeninfo fb_finfo;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080048
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070049 mMDPVersion = MDP_V_UNKNOWN;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080050 mMdpRev = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070051 mRGBPipes = 0;
52 mVGPipes = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080053 mDMAPipes = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070054 mFeatures = 0;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070055 mMDPUpscale = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070056 //TODO get this from driver, default for A-fam to 8
57 mMDPDownscale = 8;
Xiaoming Zhou3da712a2013-07-04 14:37:45 -040058 mFd = fb_fd;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080059
Naseer Ahmeda87da602012-07-01 23:54:19 -070060 if (ioctl(fb_fd, FBIOGET_FSCREENINFO, &fb_finfo) < 0) {
61 ALOGE("FBIOGET_FSCREENINFO failed");
Naseer Ahmeda87da602012-07-01 23:54:19 -070062 } 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 mastanbc05ef02013-09-17 19:29:32 -070067 mMDPVersion = atoi(str_ver);
Naseer Ahmeda87da602012-07-01 23:54:19 -070068 //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 mastanbc05ef02013-09-17 19:29:32 -070072 if (mMDPVersion < 100)
73 mMDPVersion *= 10;
Naseer Ahmeda87da602012-07-01 23:54:19 -070074
Sushil Chauhan07a2c762013-03-06 15:36:49 -080075 mRGBPipes = mVGPipes = 2;
76
Naseer Ahmeda87da602012-07-01 23:54:19 -070077 } else if (!strncmp(fb_finfo.id, "mdssfb", 6)) {
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070078 mMDPVersion = MDSS_V5;
79 if(!updateSysFsInfo()) {
80 ALOGE("Unable to read updateSysFsInfo");
Sushil Chauhan07a2c762013-03-06 15:36:49 -080081 }
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070082 if (mMdpRev == MDP_V3_0_4){
83 mMDPVersion = MDP_V3_0_4;
84 }
Naseer Ahmeda87da602012-07-01 23:54:19 -070085 }
Carl Vanderlip045d9c82013-05-09 16:22:32 -070086
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 Ahmeda87da602012-07-01 23:54:19 -070094 }
Saurabh Shah67a38c32013-06-10 16:23:15 -070095 mPanelType = panel_type;
Naseer Ahmed96c4c952012-07-25 18:27:14 -070096 mHasOverlay = false;
Xiaoming Zhou530f8612013-05-01 20:53:06 -040097 if((mMDPVersion >= MDP_V4_0) ||
98 (mMDPVersion == MDP_V_UNKNOWN) ||
99 (mMDPVersion == MDP_V3_0_4))
Naseer Ahmeda87da602012-07-01 23:54:19 -0700100 mHasOverlay = true;
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700101 if(mMDPVersion >= MDSS_V5) {
Sravan Kumar D.V.N29472592013-09-26 18:17:37 +0530102 char split[64] = {0};
Saurabh Shah67a38c32013-06-10 16:23:15 -0700103 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 Ahmeda87da602012-07-01 23:54:19 -0700121}
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700122
Xiaoming Zhou3da712a2013-07-04 14:37:45 -0400123MDPVersion::~MDPVersion() {
124 close(mFd);
125}
126
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700127int 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.
147bool 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 Shahbd2d0832013-04-04 14:33:08 -0700216bool MDPVersion::supportsDecimation() {
217 return mFeatures & MDP_DECIMATION_EN;
218}
219
220uint32_t MDPVersion::getMaxMDPDownscale() {
221 return mMDPDownscale;
222}
223
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800224bool MDPVersion::supportsBWC() {
225 // BWC - Bandwidth Compression
226 return (mFeatures & MDP_BWC_EN);
227}
Saurabh Shahe2474082013-05-15 16:32:13 -0700228
229bool MDPVersion::is8x26() {
Amara Venkata Mastan Manoj Kumar5fa4d602013-06-30 16:24:22 -0700230 // 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 Shahe2474082013-05-15 16:32:13 -0700241}
242
Saurabh Shah75b81b92013-08-29 17:31:17 -0700243bool MDPVersion::is8x74v2() {
Zohaib Alam4eff7902013-11-01 02:35:05 -0400244 if( mMdpRev >= MDSS_MDP_HW_REV_102 && mMdpRev < MDSS_MDP_HW_REV_200) {
Saurabh Shah75b81b92013-08-29 17:31:17 -0700245 return true;
246 }
247 return false;
248}
249
Zohaib Alam4eff7902013-11-01 02:35:05 -0400250bool MDPVersion::is8x92() {
251 if( mMdpRev >= MDSS_MDP_HW_REV_200 && mMdpRev < MDSS_MDP_HW_REV_206) {
252 return true;
253 }
254 return false;
255}
Naseer Ahmeda87da602012-07-01 23:54:19 -0700256}; //namespace qdutils
257