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