blob: c2ffb4b4901c43871bdb5a7fe0fb95dca84afdaa [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;
Saurabh Shah8ee5e892013-11-25 10:51:40 -080051 mLowBw = 0;
52 mHighBw = 0;
Sushil Chauhan07a2c762013-03-06 15:36:49 -080053
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080054 if(!updatePanelInfo()) {
55 ALOGE("Unable to read Primary Panel Information");
Naseer Ahmeda87da602012-07-01 23:54:19 -070056 }
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080057 if(!updateSysFsInfo()) {
58 ALOGE("Unable to read display sysfs node");
59 }
60 if (mMdpRev == MDP_V3_0_4){
61 mMDPVersion = MDP_V3_0_4;
62 }
63
Naseer Ahmed96c4c952012-07-25 18:27:14 -070064 mHasOverlay = false;
Xiaoming Zhou530f8612013-05-01 20:53:06 -040065 if((mMDPVersion >= MDP_V4_0) ||
66 (mMDPVersion == MDP_V_UNKNOWN) ||
67 (mMDPVersion == MDP_V3_0_4))
Naseer Ahmeda87da602012-07-01 23:54:19 -070068 mHasOverlay = true;
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080069 if(!updateSplitInfo()) {
70 ALOGE("Unable to read display split node");
Saurabh Shah67a38c32013-06-10 16:23:15 -070071 }
Naseer Ahmeda87da602012-07-01 23:54:19 -070072}
Saurabh Shahbd2d0832013-04-04 14:33:08 -070073
Xiaoming Zhou3da712a2013-07-04 14:37:45 -040074MDPVersion::~MDPVersion() {
75 close(mFd);
76}
77
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -070078int MDPVersion::tokenizeParams(char *inputParams, const char *delim,
79 char* tokenStr[], int *idx) {
80 char *tmp_token = NULL;
81 char *temp_ptr;
82 int ret = 0, index = 0;
83 if (!inputParams) {
84 return -1;
85 }
86 tmp_token = strtok_r(inputParams, delim, &temp_ptr);
87 while (tmp_token != NULL) {
88 tokenStr[index++] = tmp_token;
89 tmp_token = strtok_r(NULL, " ", &temp_ptr);
90 }
91 *idx = index;
92 return 0;
93}
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -080094// This function reads the sysfs node to read the primary panel type
95// and updates information accordingly
96bool MDPVersion::updatePanelInfo() {
97 FILE *displayDeviceFP = NULL;
98 const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
99 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
100 const char *strCmdPanel = "mipi dsi cmd panel";
101 const char *strVideoPanel = "mipi dsi video panel";
102 const char *strLVDSPanel = "lvds panel";
103 const char *strEDPPanel = "edp panel";
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700104
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800105 displayDeviceFP = fopen("/sys/class/graphics/fb0/msm_fb_type", "r");
106 if(displayDeviceFP){
107 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
108 displayDeviceFP);
109 if(strncmp(fbType, strCmdPanel, strlen(strCmdPanel)) == 0) {
110 mPanelType = MIPI_CMD_PANEL;
111 }
112 else if(strncmp(fbType, strVideoPanel, strlen(strVideoPanel)) == 0) {
113 mPanelType = MIPI_VIDEO_PANEL;
114 }
115 else if(strncmp(fbType, strLVDSPanel, strlen(strLVDSPanel)) == 0) {
116 mPanelType = LVDS_PANEL;
117 }
118 else if(strncmp(fbType, strEDPPanel, strlen(strEDPPanel)) == 0) {
119 mPanelType = EDP_PANEL;
120 }
121 fclose(displayDeviceFP);
122 return true;
123 }else {
124 return false;
125 }
126}
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700127
128// This function reads the sysfs node to read MDP capabilities
129// and parses and updates information accordingly.
130bool MDPVersion::updateSysFsInfo() {
131 FILE *sysfsFd;
132 size_t len = 0;
133 ssize_t read;
134 char *line = NULL;
135 char sysfsPath[255];
136 memset(sysfsPath, 0, sizeof(sysfsPath));
137 snprintf(sysfsPath , sizeof(sysfsPath),
138 "/sys/class/graphics/fb0/mdp/caps");
139
140 sysfsFd = fopen(sysfsPath, "rb");
141
142 if (sysfsFd == NULL) {
143 ALOGE("%s: sysFsFile file '%s' not found",
144 __FUNCTION__, sysfsPath);
145 return false;
146 } else {
147 while((read = getline(&line, &len, sysfsFd)) != -1) {
148 int index=0;
149 char *tokens[10];
150 memset(tokens, 0, sizeof(tokens));
151
152 // parse the line and update information accordingly
153 if(!tokenizeParams(line, TOKEN_PARAMS_DELIM, tokens, &index)) {
154 if(!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) {
155 mMdpRev = atoi(tokens[1]);
156 }
157 else if(!strncmp(tokens[0], "rgb_pipes", strlen("rgb_pipes"))) {
158 mRGBPipes = atoi(tokens[1]);
159 }
160 else if(!strncmp(tokens[0], "vig_pipes", strlen("vig_pipes"))) {
161 mVGPipes = atoi(tokens[1]);
162 }
163 else if(!strncmp(tokens[0], "dma_pipes", strlen("dma_pipes"))) {
164 mDMAPipes = atoi(tokens[1]);
165 }
166 else if(!strncmp(tokens[0], "max_downscale_ratio",
167 strlen("max_downscale_ratio"))) {
168 mMDPDownscale = atoi(tokens[1]);
169 }
170 else if(!strncmp(tokens[0], "max_upscale_ratio",
171 strlen("max_upscale_ratio"))) {
172 mMDPUpscale = atoi(tokens[1]);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800173 } else if(!strncmp(tokens[0], "max_bandwidth_low",
174 strlen("max_bandwidth_low"))) {
175 mLowBw = atol(tokens[1]);
176 } else if(!strncmp(tokens[0], "max_bandwidth_high",
177 strlen("max_bandwidth_high"))) {
178 mHighBw = atol(tokens[1]);
179 } else if(!strncmp(tokens[0], "features", strlen("features"))) {
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700180 for(int i=1; i<index;i++) {
181 if(!strncmp(tokens[i], "bwc", strlen("bwc"))) {
182 mFeatures |= MDP_BWC_EN;
183 }
184 else if(!strncmp(tokens[i], "decimation",
185 strlen("decimation"))) {
186 mFeatures |= MDP_DECIMATION_EN;
187 }
188 }
189 }
190 }
191 free(line);
192 line = NULL;
193 }
194 fclose(sysfsFd);
195 }
196 ALOGD_IF(DEBUG, "%s: mMDPVersion: %d mMdpRev: %x mRGBPipes:%d,"
197 "mVGPipes:%d", __FUNCTION__, mMDPVersion, mMdpRev,
198 mRGBPipes, mVGPipes);
199 ALOGD_IF(DEBUG, "%s:mDMAPipes:%d \t mMDPDownscale:%d, mFeatures:%d",
200 __FUNCTION__, mDMAPipes, mMDPDownscale, mFeatures);
Saurabh Shah8ee5e892013-11-25 10:51:40 -0800201 ALOGD_IF(DEBUG, "%s:mLowBw: %lu mHighBw: %lu", __FUNCTION__, mLowBw,
202 mHighBw);
203
manoj kumar amara venkata mastanbc05ef02013-09-17 19:29:32 -0700204 return true;
205}
206
Manoj Kumar AVMc65ec612013-11-21 09:20:29 -0800207// This function reads the sysfs node to read MDP capabilities
208// and parses and updates information accordingly.
209bool MDPVersion::updateSplitInfo() {
210 if(mMDPVersion >= MDSS_V5) {
211 char split[64] = {0};
212 FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r");
213 if(fp){
214 //Format "left right" space as delimiter
215 if(fread(split, sizeof(char), 64, fp)) {
216 mSplit.mLeft = atoi(split);
217 ALOGI_IF(mSplit.mLeft, "Left Split=%d", mSplit.mLeft);
218 char *rght = strpbrk(split, " ");
219 if(rght)
220 mSplit.mRight = atoi(rght + 1);
221 ALOGI_IF(mSplit.mRight, "Right Split=%d", mSplit.mRight);
222 }
223 } else {
224 ALOGE("Failed to open mdss_fb_split node");
225 return false;
226 }
227 if(fp)
228 fclose(fp);
229 }
230 return true;
231}
232
233
Saurabh Shahbd2d0832013-04-04 14:33:08 -0700234bool MDPVersion::supportsDecimation() {
235 return mFeatures & MDP_DECIMATION_EN;
236}
237
238uint32_t MDPVersion::getMaxMDPDownscale() {
239 return mMDPDownscale;
240}
241
Jeykumar Sankaran6cd8e7e2014-01-13 16:01:05 -0800242uint32_t MDPVersion::getMaxMDPUpscale() {
243 return mMDPUpscale;
244}
245
Sushil Chauhanbab187a2013-01-30 17:44:15 -0800246bool MDPVersion::supportsBWC() {
247 // BWC - Bandwidth Compression
248 return (mFeatures & MDP_BWC_EN);
249}
Saurabh Shahe2474082013-05-15 16:32:13 -0700250
Naseer Ahmeda87da602012-07-01 23:54:19 -0700251}; //namespace qdutils
252