mdp_version.cpp revision df991ce9e82b63e27859a4c534df4c6c9af2c915
1/*
2 * Copyright (c) 2012-2013, 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
40MDPVersion::MDPVersion()
41{
42    mMDPVersion = MDSS_V5;
43    mMdpRev = 0;
44    mRGBPipes = 0;
45    mVGPipes = 0;
46    mDMAPipes = 0;
47    mFeatures = 0;
48    mMDPUpscale = 0;
49    mMDPDownscale = 0;
50    mPanelType = NO_PANEL;
51    mLowBw = 0;
52    mHighBw = 0;
53
54    if(!updatePanelInfo()) {
55        ALOGE("Unable to read Primary Panel Information");
56    }
57    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
64    mHasOverlay = false;
65    if((mMDPVersion >= MDP_V4_0) ||
66       (mMDPVersion == MDP_V_UNKNOWN) ||
67       (mMDPVersion == MDP_V3_0_4))
68        mHasOverlay = true;
69    if(!updateSplitInfo()) {
70        ALOGE("Unable to read display split node");
71    }
72}
73
74MDPVersion::~MDPVersion() {
75    close(mFd);
76}
77
78int 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}
94// 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";
104
105    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}
127
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]);
173                } 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"))) {
180                    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);
201    ALOGD_IF(DEBUG, "%s:mLowBw: %lu mHighBw: %lu", __FUNCTION__,  mLowBw,
202            mHighBw);
203
204    return true;
205}
206
207// 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
234bool MDPVersion::supportsDecimation() {
235    return mFeatures & MDP_DECIMATION_EN;
236}
237
238uint32_t MDPVersion::getMaxMDPDownscale() {
239    return mMDPDownscale;
240}
241
242uint32_t MDPVersion::getMaxMDPUpscale() {
243    return mMDPUpscale;
244}
245
246bool MDPVersion::supportsBWC() {
247    // BWC - Bandwidth Compression
248    return (mFeatures & MDP_BWC_EN);
249}
250
251}; //namespace qdutils
252
253