blob: 0809fd0697cfb0f28e58a61ee261b80471694773 [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>
Sushil Chauhan07a2c762013-03-06 15:36:49 -080030#include <linux/msm_mdp.h>
Naseer Ahmeda87da602012-07-01 23:54:19 -070031#include "mdp_version.h"
32
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070033#define DEBUG 0
34
Naseer Ahmeda87da602012-07-01 23:54:19 -070035ANDROID_SINGLETON_STATIC_INSTANCE(qdutils::MDPVersion);
36namespace qdutils {
37
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070038#define TOKEN_PARAMS_DELIM "="
39
Naseer Ahmed96c4c952012-07-25 18:27:14 -070040MDPVersion::MDPVersion()
Naseer Ahmeda87da602012-07-01 23:54:19 -070041{
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080042 mMDPVersion = MDSS_V5;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080043 mMdpRev = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070044 mRGBPipes = 0;
45 mVGPipes = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080046 mDMAPipes = 0;
Saurabh Shahbd2d0832013-04-04 14:33:08 -070047 mFeatures = 0;
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070048 mMDPUpscale = 0;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080049 mMDPDownscale = 0;
50 mPanelType = NO_PANEL;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080051
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080052 if(!updatePanelInfo()) {
53 ALOGE("Unable to read Primary Panel Information");
Naseer Ahmeda87da602012-07-01 23:54:19 -070054 }
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080055 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 Ahmed96c4c952012-07-25 18:27:14 -070062 mHasOverlay = false;
Xiaoming Zhou530f8612013-05-01 20:53:06 -040063 if((mMDPVersion >= MDP_V4_0) ||
64 (mMDPVersion == MDP_V_UNKNOWN) ||
65 (mMDPVersion == MDP_V3_0_4))
Naseer Ahmeda87da602012-07-01 23:54:19 -070066 mHasOverlay = true;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080067 if(!updateSplitInfo()) {
68 ALOGE("Unable to read display split node");
Saurabh Shah67a38c32013-06-10 16:23:15 -070069 }
Naseer Ahmeda87da602012-07-01 23:54:19 -070070}
Saurabh Shahbd2d0832013-04-04 14:33:08 -070071
Xiaoming Zhou3da712a2013-07-04 14:37:45 -040072MDPVersion::~MDPVersion() {
73 close(mFd);
74}
75
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070076int 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 AVMc65ec612013-11-21 09:20:29 -080092// 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";
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700102
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800103 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 mastanbc05ef02013-09-17 19:29:32 -0700125
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
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800197// 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
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700224bool MDPVersion::supportsDecimation() {
225 return mFeatures & MDP_DECIMATION_EN;
226}
227
228uint32_t MDPVersion::getMaxMDPDownscale() {
229 return mMDPDownscale;
230}
231
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800232bool MDPVersion::supportsBWC() {
233 // BWC - Bandwidth Compression
234 return (mFeatures & MDP_BWC_EN);
235}
Saurabh Shahe2474082013-05-15 16:32:13 -0700236
237bool MDPVersion::is8x26() {
Amara Venkata Mastan Manoj Kumar5fa4d602013-06-30 16:24:22 -0700238 // 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 Shahe2474082013-05-15 16:32:13 -0700249}
250
Saurabh Shah75b81b92013-08-29 17:31:17 -0700251bool MDPVersion::is8x74v2() {
Zohaib Alam4eff7902013-11-01 02:35:05 -0400252 if( mMdpRev >= MDSS_MDP_HW_REV_102 && mMdpRev < MDSS_MDP_HW_REV_200) {
Saurabh Shah75b81b92013-08-29 17:31:17 -0700253 return true;
254 }
255 return false;
256}
257
Zohaib Alam4eff7902013-11-01 02:35:05 -0400258bool 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 Ahmeda87da602012-07-01 23:54:19 -0700264}; //namespace qdutils
265