mdp_version.cpp revision c0fbcede3ccc2e0996531f29cccdf02b47ba70ad
1/*
2 * Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
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.
13 *   * Neither the name of The Linux Foundation nor the names of its
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 <linux/msm_mdp.h>
31#include "mdp_version.h"
32
33#define DEBUG 0
34
35ANDROID_SINGLETON_STATIC_INSTANCE(qdutils::MDPVersion);
36namespace qdutils {
37
38#define TOKEN_PARAMS_DELIM  "="
39
40#ifndef MDSS_MDP_REV
41enum mdp_rev {
42    MDSS_MDP_HW_REV_100 = 0x10000000, //8974 v1
43    MDSS_MDP_HW_REV_101 = 0x10010000, //8x26
44    MDSS_MDP_HW_REV_102 = 0x10020000, //8974 v2
45    MDSS_MDP_HW_REV_103 = 0x10030000, //8084
46    MDSS_MDP_HW_REV_104 = 0x10040000, //Next version
47    MDSS_MDP_HW_REV_105 = 0x10050000, //Next version
48    MDSS_MDP_HW_REV_107 = 0x10070000, //Next version
49    MDSS_MDP_HW_REV_200 = 0x20000000, //8092
50    MDSS_MDP_HW_REV_206 = 0x20060000, //Future
51};
52#else
53enum mdp_rev {
54    MDSS_MDP_HW_REV_104 = 0x10040000, //Next version
55    MDSS_MDP_HW_REV_206 = 0x20060000, //Future
56};
57#endif
58
59MDPVersion::MDPVersion()
60{
61    mMDPVersion = MDSS_V5;
62    mMdpRev = 0;
63    mRGBPipes = 0;
64    mVGPipes = 0;
65    mDMAPipes = 0;
66    mFeatures = 0;
67    mMDPUpscale = 0;
68    mMDPDownscale = 0;
69    mMacroTileEnabled = false;
70    mPanelType = NO_PANEL;
71    mLowBw = 0;
72    mHighBw = 0;
73
74    if(!updatePanelInfo()) {
75        ALOGE("Unable to read Primary Panel Information");
76    }
77    if(!updateSysFsInfo()) {
78        ALOGE("Unable to read display sysfs node");
79    }
80    if (mMdpRev == MDP_V3_0_4){
81        mMDPVersion = MDP_V3_0_4;
82    }
83
84    mHasOverlay = false;
85    if((mMDPVersion >= MDP_V4_0) ||
86       (mMDPVersion == MDP_V_UNKNOWN) ||
87       (mMDPVersion == MDP_V3_0_4))
88        mHasOverlay = true;
89    if(!updateSplitInfo()) {
90        ALOGE("Unable to read display split node");
91    }
92}
93
94MDPVersion::~MDPVersion() {
95    close(mFd);
96}
97
98int MDPVersion::tokenizeParams(char *inputParams, const char *delim,
99                                char* tokenStr[], int *idx) {
100    char *tmp_token = NULL;
101    char *temp_ptr;
102    int index = 0;
103    if (!inputParams) {
104        return -1;
105    }
106    tmp_token = strtok_r(inputParams, delim, &temp_ptr);
107    while (tmp_token != NULL) {
108        tokenStr[index++] = tmp_token;
109        tmp_token = strtok_r(NULL, " ", &temp_ptr);
110    }
111    *idx = index;
112    return 0;
113}
114// This function reads the sysfs node to read the primary panel type
115// and updates information accordingly
116bool MDPVersion::updatePanelInfo() {
117    FILE *displayDeviceFP = NULL;
118    const int MAX_FRAME_BUFFER_NAME_SIZE = 128;
119    char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
120    const char *strCmdPanel = "mipi dsi cmd panel";
121    const char *strVideoPanel = "mipi dsi video panel";
122    const char *strLVDSPanel = "lvds panel";
123    const char *strEDPPanel = "edp panel";
124
125    displayDeviceFP = fopen("/sys/class/graphics/fb0/msm_fb_type", "r");
126    if(displayDeviceFP){
127        fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
128                displayDeviceFP);
129        if(strncmp(fbType, strCmdPanel, strlen(strCmdPanel)) == 0) {
130            mPanelType = MIPI_CMD_PANEL;
131        }
132        else if(strncmp(fbType, strVideoPanel, strlen(strVideoPanel)) == 0) {
133            mPanelType = MIPI_VIDEO_PANEL;
134        }
135        else if(strncmp(fbType, strLVDSPanel, strlen(strLVDSPanel)) == 0) {
136            mPanelType = LVDS_PANEL;
137        }
138        else if(strncmp(fbType, strEDPPanel, strlen(strEDPPanel)) == 0) {
139            mPanelType = EDP_PANEL;
140        }
141        fclose(displayDeviceFP);
142        return true;
143    }else {
144        return false;
145    }
146}
147
148// This function reads the sysfs node to read MDP capabilities
149// and parses and updates information accordingly.
150bool MDPVersion::updateSysFsInfo() {
151    FILE *sysfsFd;
152    size_t len = PAGE_SIZE;
153    ssize_t read;
154    char *line = NULL;
155    char sysfsPath[255];
156    memset(sysfsPath, 0, sizeof(sysfsPath));
157    snprintf(sysfsPath , sizeof(sysfsPath),
158            "/sys/class/graphics/fb0/mdp/caps");
159    char property[PROPERTY_VALUE_MAX];
160    bool enableMacroTile = false;
161
162    if((property_get("persist.hwc.macro_tile_enable", property, NULL) > 0) &&
163       (!strncmp(property, "1", PROPERTY_VALUE_MAX ) ||
164        (!strncasecmp(property,"true", PROPERTY_VALUE_MAX )))) {
165        enableMacroTile = true;
166    }
167
168    sysfsFd = fopen(sysfsPath, "rb");
169
170    if (sysfsFd == NULL) {
171        ALOGE("%s: sysFsFile file '%s' not found",
172                __FUNCTION__, sysfsPath);
173        return false;
174    } else {
175        line = (char *) malloc(len);
176        while((read = getline(&line, &len, sysfsFd)) != -1) {
177            int index=0;
178            char *tokens[10];
179            memset(tokens, 0, sizeof(tokens));
180
181            // parse the line and update information accordingly
182            if(!tokenizeParams(line, TOKEN_PARAMS_DELIM, tokens, &index)) {
183                if(!strncmp(tokens[0], "hw_rev", strlen("hw_rev"))) {
184                    mMdpRev = atoi(tokens[1]);
185                }
186                else if(!strncmp(tokens[0], "rgb_pipes", strlen("rgb_pipes"))) {
187                    mRGBPipes = atoi(tokens[1]);
188                }
189                else if(!strncmp(tokens[0], "vig_pipes", strlen("vig_pipes"))) {
190                    mVGPipes = atoi(tokens[1]);
191                }
192                else if(!strncmp(tokens[0], "dma_pipes", strlen("dma_pipes"))) {
193                    mDMAPipes = atoi(tokens[1]);
194                }
195                else if(!strncmp(tokens[0], "max_downscale_ratio",
196                                strlen("max_downscale_ratio"))) {
197                    mMDPDownscale = atoi(tokens[1]);
198                }
199                else if(!strncmp(tokens[0], "max_upscale_ratio",
200                                strlen("max_upscale_ratio"))) {
201                    mMDPUpscale = atoi(tokens[1]);
202                } else if(!strncmp(tokens[0], "max_bandwidth_low",
203                        strlen("max_bandwidth_low"))) {
204                    mLowBw = atol(tokens[1]);
205                } else if(!strncmp(tokens[0], "max_bandwidth_high",
206                        strlen("max_bandwidth_high"))) {
207                    mHighBw = atol(tokens[1]);
208                } else if(!strncmp(tokens[0], "features", strlen("features"))) {
209                    for(int i=1; i<index;i++) {
210                        if(!strncmp(tokens[i], "bwc", strlen("bwc"))) {
211                           mFeatures |= MDP_BWC_EN;
212                        }
213                        else if(!strncmp(tokens[i], "decimation",
214                                    strlen("decimation"))) {
215                           mFeatures |= MDP_DECIMATION_EN;
216                        }
217                        else if(!strncmp(tokens[i], "tile_format",
218                                    strlen("tile_format"))) {
219                           if(enableMacroTile)
220                               mMacroTileEnabled = true;
221                        }
222                    }
223                }
224            }
225        }
226        free(line);
227        fclose(sysfsFd);
228    }
229    ALOGD_IF(DEBUG, "%s: mMDPVersion: %d mMdpRev: %x mRGBPipes:%d,"
230                    "mVGPipes:%d", __FUNCTION__, mMDPVersion, mMdpRev,
231                    mRGBPipes, mVGPipes);
232    ALOGD_IF(DEBUG, "%s:mDMAPipes:%d \t mMDPDownscale:%d, mFeatures:%d",
233                     __FUNCTION__,  mDMAPipes, mMDPDownscale, mFeatures);
234    ALOGD_IF(DEBUG, "%s:mLowBw: %lu mHighBw: %lu", __FUNCTION__,  mLowBw,
235            mHighBw);
236
237    return true;
238}
239
240// This function reads the sysfs node to read MDP capabilities
241// and parses and updates information accordingly.
242bool MDPVersion::updateSplitInfo() {
243    if(mMDPVersion >= MDSS_V5) {
244        char split[64] = {0};
245        FILE* fp = fopen("/sys/class/graphics/fb0/msm_fb_split", "r");
246        if(fp){
247            //Format "left right" space as delimiter
248            if(fread(split, sizeof(char), 64, fp)) {
249                mSplit.mLeft = atoi(split);
250                ALOGI_IF(mSplit.mLeft, "Left Split=%d", mSplit.mLeft);
251                char *rght = strpbrk(split, " ");
252                if(rght)
253                    mSplit.mRight = atoi(rght + 1);
254                ALOGI_IF(mSplit.mRight, "Right Split=%d", mSplit.mRight);
255            }
256        } else {
257            ALOGE("Failed to open mdss_fb_split node");
258            return false;
259        }
260        if(fp)
261            fclose(fp);
262    }
263    return true;
264}
265
266
267bool MDPVersion::supportsDecimation() {
268    return mFeatures & MDP_DECIMATION_EN;
269}
270
271uint32_t MDPVersion::getMaxMDPDownscale() {
272    return mMDPDownscale;
273}
274
275uint32_t MDPVersion::getMaxMDPUpscale() {
276    return mMDPUpscale;
277}
278
279bool MDPVersion::supportsBWC() {
280    // BWC - Bandwidth Compression
281    return (mFeatures & MDP_BWC_EN);
282}
283
284bool MDPVersion::supportsMacroTile() {
285    // MACRO TILE support
286    return mMacroTileEnabled;
287}
288
289bool MDPVersion::is8x26() {
290    return (mMdpRev >= MDSS_MDP_HW_REV_101 and
291            mMdpRev < MDSS_MDP_HW_REV_102);
292}
293
294bool MDPVersion::is8x74v2() {
295    return (mMdpRev >= MDSS_MDP_HW_REV_102 and
296            mMdpRev < MDSS_MDP_HW_REV_103);
297}
298
299bool MDPVersion::is8084() {
300    return (mMdpRev >= MDSS_MDP_HW_REV_103 and
301            mMdpRev < MDSS_MDP_HW_REV_104);
302}
303
304bool MDPVersion::is8092() {
305    return (mMdpRev >= MDSS_MDP_HW_REV_200 and
306            mMdpRev < MDSS_MDP_HW_REV_206);
307}
308
309}; //namespace qdutils
310
311