external.cpp revision 474d24afc2f7702a8341a622f8877a2631a9ae28
10c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed/*
20c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * Copyright (C) 2010 The Android Open Source Project
356f610dd235b577725198e9341caae92379fdf23Saurabh Shah * Copyright (C) 2012, The Linux Foundation. All rights reserved.
40c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed *
50c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * Not a Contribution, Apache license notifications and license are
60c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * retained for attribution purposes only.
70c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed *
80c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * Licensed under the Apache License, Version 2.0 (the "License");
90c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * you may not use this file except in compliance with the License.
100c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * You may obtain a copy of the License at
110c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed *
120c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed *      http://www.apache.org/licenses/LICENSE-2.0
130c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed *
140c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * Unless required by applicable law or agreed to in writing, software
150c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * distributed under the License is distributed on an "AS IS" BASIS,
160c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
170c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * See the License for the specific language governing permissions and
180c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed * limitations under the License.
190c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed */
200c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
2172cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed#define DEBUG 0
220c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <ctype.h>
2372cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed#include <fcntl.h>
240c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <media/IAudioPolicyService.h>
250c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <media/AudioSystem.h>
260c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <utils/threads.h>
270c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <utils/Errors.h>
280c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <utils/Log.h>
290c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
300c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <linux/msm_mdp.h>
310c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <linux/fb.h>
320c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <sys/ioctl.h>
330c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <sys/poll.h>
3472cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed#include <sys/resource.h>
350c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include <cutils/properties.h>
360c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#include "hwc_utils.h"
3756f610dd235b577725198e9341caae92379fdf23Saurabh Shah#include "external.h"
3856f610dd235b577725198e9341caae92379fdf23Saurabh Shah#include "overlayUtils.h"
39c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar#include "overlay.h"
4056f610dd235b577725198e9341caae92379fdf23Saurabh Shah
4156f610dd235b577725198e9341caae92379fdf23Saurabh Shahusing namespace android;
420c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
430c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmednamespace qhwc {
440c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
45c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar#define MAX_FRAME_BUFFER_NAME_SIZE      (80)
46c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar#define MAX_DISPLAY_DEVICES             (3)
47c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
48c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
49c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarconst char* msmFbDevicePath[] = {  "/dev/graphics/fb1",
50c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                                   "/dev/graphics/fb2"};
51c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
52c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar/*
53c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar * Updates extDeviceFbIndex Array with the correct frame buffer indices
54c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar * of avaiable external devices
55c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar *
56c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar */
57c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarvoid ExternalDisplay::updateExtDispDevFbIndex()
58c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar{
59c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    FILE *displayDeviceFP = NULL;
60c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
61c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
62c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
63c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    for(int j = 1; j < MAX_DISPLAY_DEVICES; j++) {
64c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        sprintf (msmFbTypePath,"/sys/class/graphics/fb%d/msm_fb_type", j);
65c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        displayDeviceFP = fopen(msmFbTypePath, "r");
66c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        if(displayDeviceFP){
67c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar            fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
68c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                    displayDeviceFP);
69c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar            if(strncmp(fbType, "dtv panel", strlen("dtv panel")) == 0){
70c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                ALOGD_IF(DEBUG,"hdmi framebuffer index is %d",j);
71c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                mHdmiFbNum = j;
72c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar            } else if(strncmp(fbType, "writeback panel",
73c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                                    strlen("writeback panel")) == 0){
74c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                ALOGD_IF(DEBUG,"wfd framebuffer index is %d",j);
75c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                mWfdFbNum = j;
76c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar            }
77c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar            fclose(displayDeviceFP);
78c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        }
79c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }
80c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    ALOGD_IF(DEBUG,"%s: mHdmiFbNum: %d mWfdFbNum: %d ",__FUNCTION__,
81c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                                                       mHdmiFbNum, mWfdFbNum);
82c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar}
83c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
84c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarint ExternalDisplay::configureHDMIDisplay() {
85c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    openFrameBuffer(mHdmiFbNum);
86c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(mFd == -1)
87c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        return -1;
884012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    readCEUnderscanInfo();
89c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    readResolution();
90c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    // TODO: Move this to activate
91f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    /* Used for changing the resolution
92f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R     * getUserMode will get the preferred
93f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R     * mode set thru adb shell */
94f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    int mode = getUserMode();
95f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    if (mode == -1) {
96f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        //Get the best mode and set
97f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        mode = getBestMode();
98f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    }
99f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    setResolution(mode);
100c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    setDpyHdmiAttr();
101c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    setExternalDisplay(true, mHdmiFbNum);
102c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    return 0;
103c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar}
104c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
105c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarint ExternalDisplay::configureWFDDisplay() {
106c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    int ret = 0;
107c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(mConnectedFbNum == mHdmiFbNum) {
108c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        ALOGE("%s: Cannot process WFD connection while HDMI is active",
109c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                     __FUNCTION__);
110c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        return -1;
111c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }
112c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    openFrameBuffer(mWfdFbNum);
113c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(mFd == -1)
114c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        return -1;
115c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
116c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(ret < 0) {
117c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
118c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                strerror(errno));
119c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }
120c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    setDpyWfdAttr();
121c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    setExternalDisplay(true, mWfdFbNum);
122c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    return 0;
123c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar}
124c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
125c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarint ExternalDisplay::teardownHDMIDisplay() {
126c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(mConnectedFbNum == mHdmiFbNum) {
127c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        // hdmi offline event..!
128c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        closeFrameBuffer();
129c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        resetInfo();
130c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        setExternalDisplay(false);
131c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }
132c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    return 0;
133c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar}
1340c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
135c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarint ExternalDisplay::teardownWFDDisplay() {
136c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(mConnectedFbNum == mWfdFbNum) {
137c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        // wfd offline event..!
138c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        closeFrameBuffer();
139c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        memset(&mVInfo, 0, sizeof(mVInfo));
140c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        setExternalDisplay(false);
141c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }
142c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    return 0;
143c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar}
1440c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
145c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarvoid ExternalDisplay::processUEventOnline(const char *str) {
146c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    const char *s1 = str + strlen("change@/devices/virtual/switch/");
147c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(!strncmp(s1,"hdmi",strlen(s1))) {
148c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        // hdmi online event..!
149c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        configureHDMIDisplay();
150358d2dd774971c048057dbf85d594f5aa02af8eeArun Kumar K.R        // set system property
151358d2dd774971c048057dbf85d594f5aa02af8eeArun Kumar K.R        property_set("hw.hdmiON", "1");
152c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }else if(!strncmp(s1,"wfd",strlen(s1))) {
153c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        // wfd online event..!
154c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        configureWFDDisplay();
155c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }
156c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar}
1570c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
158c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarvoid ExternalDisplay::processUEventOffline(const char *str) {
159c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    const char *s1 = str + strlen("change@/devices/virtual/switch/");
160c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(!strncmp(s1,"hdmi",strlen(s1))) {
161c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        teardownHDMIDisplay();
162358d2dd774971c048057dbf85d594f5aa02af8eeArun Kumar K.R        // unset system property
163358d2dd774971c048057dbf85d594f5aa02af8eeArun Kumar K.R        property_set("hw.hdmiON", "0");
164c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }else if(!strncmp(s1,"wfd",strlen(s1))) {
165c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        teardownWFDDisplay();
166c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }
167c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar}
1680c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
169f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer AhmedExternalDisplay::ExternalDisplay(hwc_context_t* ctx):mFd(-1),
170c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    mCurrentMode(-1), mConnected(0), mConnectedFbNum(0), mModeCount(0),
1713a85d3e5b8f689cb3a3ef7ef1ce50c1e01afae1aAmara Venkata Mastan Manoj Kumar    mUnderscanSupported(false), mHwcContext(ctx), mHdmiFbNum(-1),
1723a85d3e5b8f689cb3a3ef7ef1ce50c1e01afae1aAmara Venkata Mastan Manoj Kumar    mWfdFbNum(-1), mExtDpyNum(HWC_DISPLAY_EXTERNAL)
1730c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
174f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    memset(&mVInfo, 0, sizeof(mVInfo));
175c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    //Determine the fb index for external display devices.
176c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    updateExtDispDevFbIndex();
1773a85d3e5b8f689cb3a3ef7ef1ce50c1e01afae1aAmara Venkata Mastan Manoj Kumar
1780c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
1790c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
18056f610dd235b577725198e9341caae92379fdf23Saurabh Shahvoid ExternalDisplay::setEDIDMode(int resMode) {
18156f610dd235b577725198e9341caae92379fdf23Saurabh Shah    ALOGD_IF(DEBUG,"resMode=%d ", resMode);
18256f610dd235b577725198e9341caae92379fdf23Saurabh Shah    {
18356f610dd235b577725198e9341caae92379fdf23Saurabh Shah        Mutex::Autolock lock(mExtDispLock);
184c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        setExternalDisplay(false);
185c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        openFrameBuffer(mHdmiFbNum);
18656f610dd235b577725198e9341caae92379fdf23Saurabh Shah        setResolution(resMode);
18756f610dd235b577725198e9341caae92379fdf23Saurabh Shah    }
188c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    setExternalDisplay(true, mHdmiFbNum);
18956f610dd235b577725198e9341caae92379fdf23Saurabh Shah}
19056f610dd235b577725198e9341caae92379fdf23Saurabh Shah
19156f610dd235b577725198e9341caae92379fdf23Saurabh Shahvoid ExternalDisplay::setHPD(uint32_t startEnd) {
19256f610dd235b577725198e9341caae92379fdf23Saurabh Shah    ALOGD_IF(DEBUG,"HPD enabled=%d", startEnd);
19356f610dd235b577725198e9341caae92379fdf23Saurabh Shah    writeHPDOption(startEnd);
19456f610dd235b577725198e9341caae92379fdf23Saurabh Shah}
19556f610dd235b577725198e9341caae92379fdf23Saurabh Shah
19656f610dd235b577725198e9341caae92379fdf23Saurabh Shahvoid ExternalDisplay::setActionSafeDimension(int w, int h) {
19756f610dd235b577725198e9341caae92379fdf23Saurabh Shah    ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h);
19856f610dd235b577725198e9341caae92379fdf23Saurabh Shah    Mutex::Autolock lock(mExtDispLock);
1994012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    char actionsafeWidth[PROPERTY_VALUE_MAX];
2004012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    char actionsafeHeight[PROPERTY_VALUE_MAX];
2014012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    sprintf(actionsafeWidth, "%d", w);
2024012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    property_set("hw.actionsafe.width", actionsafeWidth);
2034012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    sprintf(actionsafeHeight, "%d", h);
2044012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    property_set("hw.actionsafe.height", actionsafeHeight);
205c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    setExternalDisplay(true, mHdmiFbNum);
20656f610dd235b577725198e9341caae92379fdf23Saurabh Shah}
20756f610dd235b577725198e9341caae92379fdf23Saurabh Shah
20856f610dd235b577725198e9341caae92379fdf23Saurabh Shahint ExternalDisplay::getModeCount() const {
20956f610dd235b577725198e9341caae92379fdf23Saurabh Shah    ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount);
21056f610dd235b577725198e9341caae92379fdf23Saurabh Shah    Mutex::Autolock lock(mExtDispLock);
21156f610dd235b577725198e9341caae92379fdf23Saurabh Shah    return mModeCount;
21256f610dd235b577725198e9341caae92379fdf23Saurabh Shah}
21356f610dd235b577725198e9341caae92379fdf23Saurabh Shah
21456f610dd235b577725198e9341caae92379fdf23Saurabh Shahvoid ExternalDisplay::getEDIDModes(int *out) const {
21556f610dd235b577725198e9341caae92379fdf23Saurabh Shah    Mutex::Autolock lock(mExtDispLock);
21656f610dd235b577725198e9341caae92379fdf23Saurabh Shah    for(int i = 0;i < mModeCount;i++) {
21756f610dd235b577725198e9341caae92379fdf23Saurabh Shah        out[i] = mEDIDModes[i];
21856f610dd235b577725198e9341caae92379fdf23Saurabh Shah    }
21956f610dd235b577725198e9341caae92379fdf23Saurabh Shah}
22056f610dd235b577725198e9341caae92379fdf23Saurabh Shah
2214012258b6b344adccf19973602c4d092e2403053Arun Kumar K.Rvoid ExternalDisplay::readCEUnderscanInfo()
2224012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R{
2234012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    int hdmiScanInfoFile = -1;
2244012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    int len = -1;
2254012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    char scanInfo[17];
2264012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    char *ce_info_str = NULL;
2274012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    const char token[] = ", \n";
2284012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    int ce_info = -1;
2294012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    char sysFsScanInfoFilePath[128];
2304012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    sprintf(sysFsScanInfoFilePath, "/sys/devices/virtual/graphics/fb%d/"
2314012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R                                   "scan_info", mHdmiFbNum);
2324012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R
2334012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    memset(scanInfo, 0, sizeof(scanInfo));
2344012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    hdmiScanInfoFile = open(sysFsScanInfoFilePath, O_RDONLY, 0);
2354012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    if (hdmiScanInfoFile < 0) {
2364012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        ALOGD_IF(DEBUG, "%s: scan_info file '%s' not found",
2374012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R                                __FUNCTION__, sysFsScanInfoFilePath);
2384012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        return;
2394012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    } else {
2404012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        len = read(hdmiScanInfoFile, scanInfo, sizeof(scanInfo)-1);
2414012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        ALOGD("%s: Scan Info string: %s length = %d",
2424012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R                 __FUNCTION__, scanInfo, len);
2434012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        if (len <= 0) {
2444012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            close(hdmiScanInfoFile);
2454012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            ALOGE("%s: Scan Info file empty '%s'",
2464012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R                                __FUNCTION__, sysFsScanInfoFilePath);
2474012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            return;
2484012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        }
2494012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        scanInfo[len] = '\0';  /* null terminate the string */
2504012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    }
2514012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    close(hdmiScanInfoFile);
2524012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R
2534012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    /*
2544012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R     * The scan_info contains the three fields
2554012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R     * PT - preferred video format
2564012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R     * IT - video format
2574012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R     * CE video format - containing the underscan support information
2584012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R     */
2594012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R
2604012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    /* PT */
2614012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    ce_info_str = strtok(scanInfo, token);
2624012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    if (ce_info_str) {
2634012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        /* IT */
2644012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        ce_info_str = strtok(NULL, token);
2654012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        if (ce_info_str) {
2664012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            /* CE */
2674012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            ce_info_str = strtok(NULL, token);
2684012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            if (ce_info_str)
2694012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R                ce_info = atoi(ce_info_str);
2704012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        }
2714012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    }
2724012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R
2734012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    if (ce_info_str) {
2744012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        // ce_info contains the underscan information
2754012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        if (ce_info == EXT_SCAN_ALWAYS_UNDERSCANED ||
2764012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            ce_info == EXT_SCAN_BOTH_SUPPORTED)
2774012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            // if TV supported underscan, then driver will always underscan
2784012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            // hence no need to apply action safe rectangle
2794012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R            mUnderscanSupported = true;
2804012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    } else {
2814012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R        ALOGE("%s: scan_info string error", __FUNCTION__);
2824012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    }
2834012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R
2844012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    // Store underscan support info in a system property
2854012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    const char* prop = (mUnderscanSupported) ? "1" : "0";
2864012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    property_set("hw.underscan_supported", prop);
2874012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    return;
2884012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R}
2894012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R
29072cf9762f84aab07faab86e35fe830b63ec54d72Naseer AhmedExternalDisplay::~ExternalDisplay()
29172cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed{
292f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    closeFrameBuffer();
2930c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
2940c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
2950c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmedstruct disp_mode_timing_type {
2960c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  video_format;
2970c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
2980c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  active_h;
2990c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  active_v;
3000c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
3010c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  front_porch_h;
3020c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  pulse_width_h;
3030c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  back_porch_h;
3040c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
3050c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  front_porch_v;
3060c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  pulse_width_v;
3070c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  back_porch_v;
3080c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
3090c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int  pixel_freq;
3100c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    bool interlaced;
3110c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
3120c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    void set_info(struct fb_var_screeninfo &info) const;
3130c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed};
3140c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
3150c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmedvoid disp_mode_timing_type::set_info(struct fb_var_screeninfo &info) const
3160c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
3170c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.reserved[0] = 0;
3180c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.reserved[1] = 0;
3190c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.reserved[2] = 0;
3202310d4e7739b173b950a89c604c553e3302349f5Ken Zhang#ifndef FB_METADATA_VIDEO_INFO_CODE_SUPPORT
32156f610dd235b577725198e9341caae92379fdf23Saurabh Shah    info.reserved[3] = (info.reserved[3] & 0xFFFF) | (video_format << 16);
3222310d4e7739b173b950a89c604c553e3302349f5Ken Zhang#endif
3230c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.xoffset = 0;
3240c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.yoffset = 0;
3250c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.xres = active_h;
3260c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.yres = active_v;
3270c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
3280c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.pixclock = pixel_freq*1000;
3290c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.vmode = interlaced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED;
3300c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
3310c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.right_margin = front_porch_h;
3320c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.hsync_len = pulse_width_h;
3330c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.left_margin = back_porch_h;
3340c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.lower_margin = front_porch_v;
3350c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.vsync_len = pulse_width_v;
3360c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    info.upper_margin = back_porch_v;
3370c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
3380c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
3390c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed/* Video formates supported by the HDMI Standard */
3400c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed/* Indicates the resolution, pix clock and the aspect ratio */
3410c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m640x480p60_4_3         1
3420c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m720x480p60_4_3         2
3430c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m720x480p60_16_9        3
3440c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1280x720p60_16_9       4
3450c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1920x1080i60_16_9      5
3460c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1440x480i60_4_3        6
3470c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1440x480i60_16_9       7
3480c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1920x1080p60_16_9      16
3490c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m720x576p50_4_3         17
3500c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m720x576p50_16_9        18
3510c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1280x720p50_16_9       19
3520c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1440x576i50_4_3        21
3530c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1440x576i50_16_9       22
3540c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1920x1080p50_16_9      31
3550c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1920x1080p24_16_9      32
3560c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1920x1080p25_16_9      33
3570c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed#define m1920x1080p30_16_9      34
3580c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
3590c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmedstatic struct disp_mode_timing_type supported_video_mode_lut[] = {
3600c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m640x480p60_4_3,     640,  480,  16,  96,  48, 10, 2, 33,  25200, false},
3610c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m720x480p60_4_3,     720,  480,  16,  62,  60,  9, 6, 30,  27030, false},
3620c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m720x480p60_16_9,    720,  480,  16,  62,  60,  9, 6, 30,  27030, false},
3630c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1280x720p60_16_9,  1280,  720, 110,  40, 220,  5, 5, 20,  74250, false},
3640c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1920x1080i60_16_9, 1920,  540,  88,  44, 148,  2, 5,  5,  74250, false},
3650c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1440x480i60_4_3,   1440,  240,  38, 124, 114,  4, 3, 15,  27000, true},
3660c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1440x480i60_16_9,  1440,  240,  38, 124, 114,  4, 3, 15,  27000, true},
3670c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1920x1080p60_16_9, 1920, 1080,  88,  44, 148,  4, 5, 36, 148500, false},
3680c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m720x576p50_4_3,     720,  576,  12,  64,  68,  5, 5, 39,  27000, false},
3690c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m720x576p50_16_9,    720,  576,  12,  64,  68,  5, 5, 39,  27000, false},
3700c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1280x720p50_16_9,  1280,  720, 440,  40, 220,  5, 5, 20,  74250, false},
3710c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1440x576i50_4_3,   1440,  288,  24, 126, 138,  2, 3, 19,  27000, true},
3720c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1440x576i50_16_9,  1440,  288,  24, 126, 138,  2, 3, 19,  27000, true},
3730c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1920x1080p50_16_9, 1920, 1080, 528,  44, 148,  4, 5, 36, 148500, false},
3740c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1920x1080p24_16_9, 1920, 1080, 638,  44, 148,  4, 5, 36,  74250, false},
3750c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1920x1080p25_16_9, 1920, 1080, 528,  44, 148,  4, 5, 36,  74250, false},
3760c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    {m1920x1080p30_16_9, 1920, 1080,  88,  44, 148,  4, 5, 36,  74250, false},
3770c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed};
37872cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed
379f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmedint ExternalDisplay::parseResolution(char* edidStr, int* edidModes)
3800c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
3810c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    char delim = ',';
3820c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int count = 0;
3830c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    char *start, *end;
3840c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    // EDIDs are string delimited by ','
3850c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    // Ex: 16,4,5,3,32,34,1
3860c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    // Parse this string to get mode(int)
3870c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    start = (char*) edidStr;
388f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    end = &delim;
389f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    while(*end == delim) {
390f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        edidModes[count] = (int) strtol(start, &end, 10);
3910c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        start = end+1;
3920c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        count++;
3930c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    }
394f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count);
395f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    for (int i = 0; i < count; i++)
396f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        ALOGD_IF(DEBUG, "Mode[%d] = %d", i, edidModes[i]);
3970c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    return count;
3980c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
399f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed
40072cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmedbool ExternalDisplay::readResolution()
4010c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
402c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    char sysFsEDIDFilePath[255];
403c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    sprintf(sysFsEDIDFilePath , "/sys/devices/virtual/graphics/fb%d/edid_modes",
404c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar            mHdmiFbNum);
405c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
406c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    int hdmiEDIDFile = open(sysFsEDIDFilePath, O_RDONLY, 0);
4070c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int len = -1;
4080c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
4090c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    if (hdmiEDIDFile < 0) {
410f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        ALOGE("%s: edid_modes file '%s' not found",
411c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                 __FUNCTION__, sysFsEDIDFilePath);
4120c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        return false;
4130c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    } else {
4140c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1);
41572cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed        ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d",
41672cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed                 __FUNCTION__, mEDIDs, len);
4170c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        if ( len <= 0) {
418f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed            ALOGE("%s: edid_modes file empty '%s'",
419c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                     __FUNCTION__, sysFsEDIDFilePath);
4200c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        }
4210c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        else {
4220c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            while (len > 1 && isspace(mEDIDs[len-1]))
4230c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed                --len;
4240c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            mEDIDs[len] = 0;
4250c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        }
4260c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    }
4270c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    close(hdmiEDIDFile);
4280c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    if(len > 0) {
429c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        // Get EDID modes from the EDID strings
430f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        mModeCount = parseResolution(mEDIDs, mEDIDModes);
43172cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed        ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__,
43272cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed                 mModeCount);
4330c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    }
4340c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
4350c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    return (strlen(mEDIDs) > 0);
4360c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
4370c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
438c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarbool ExternalDisplay::openFrameBuffer(int fbNum)
4390c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
440f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    if (mFd == -1) {
441c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        mFd = open(msmFbDevicePath[fbNum-1], O_RDWR);
442f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        if (mFd < 0)
443c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar            ALOGE("%s: %s is not available", __FUNCTION__,
444c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                                            msmFbDevicePath[fbNum-1]);
445c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        if(mHwcContext) {
4463a85d3e5b8f689cb3a3ef7ef1ce50c1e01afae1aAmara Venkata Mastan Manoj Kumar            mHwcContext->dpyAttr[mExtDpyNum].fd = mFd;
447c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        }
4483e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah    }
449f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    return (mFd > 0);
450f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed}
451f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed
452f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmedbool ExternalDisplay::closeFrameBuffer()
453f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed{
454f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    int ret = 0;
455d09406b9b8f3b6e9d84ba28ed10cb3165d96c875Naseer Ahmed    if(mFd >= 0) {
456f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        ret = close(mFd);
457f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        mFd = -1;
4580c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    }
4593e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah    if(mHwcContext) {
4603a85d3e5b8f689cb3a3ef7ef1ce50c1e01afae1aAmara Venkata Mastan Manoj Kumar        mHwcContext->dpyAttr[mExtDpyNum].fd = mFd;
4613e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah    }
462f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    return (ret == 0);
4630c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
4640c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
465f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed// clears the vinfo, edid, best modes
466f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmedvoid ExternalDisplay::resetInfo()
467f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed{
468f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    memset(&mVInfo, 0, sizeof(mVInfo));
469f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    memset(mEDIDs, 0, sizeof(mEDIDs));
470f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    memset(mEDIDModes, 0, sizeof(mEDIDModes));
471f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    mModeCount = 0;
472f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    mCurrentMode = -1;
4734012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    mUnderscanSupported = false;
4744012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    // Reset the underscan supported system property
4754012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    const char* prop = "0";
4764012258b6b344adccf19973602c4d092e2403053Arun Kumar K.R    property_set("hw.underscan_supported", prop);
477f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed}
4780c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
47972cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmedint ExternalDisplay::getModeOrder(int mode)
4800c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
481f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    // XXX: We dont support interlaced modes but having
482f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    // it here for for future
4830c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    switch (mode) {
4840c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        default:
4850c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1440x480i60_4_3:
4860c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 1; // 480i 4:3
4870c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1440x480i60_16_9:
4880c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 2; // 480i 16:9
4890c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1440x576i50_4_3:
4900c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 3; // i576i 4:3
4910c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1440x576i50_16_9:
4920c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 4; // 576i 16:9
4930c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m640x480p60_4_3:
4940c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 5; // 640x480 4:3
4950c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m720x480p60_4_3:
4960c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 6; // 480p 4:3
4970c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m720x480p60_16_9:
4980c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 7; // 480p 16:9
4990c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m720x576p50_4_3:
5000c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 8; // 576p 4:3
5010c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m720x576p50_16_9:
5020c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 9; // 576p 16:9
5030c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1920x1080i60_16_9:
5040c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 10; // 1080i 16:9
5050c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1280x720p50_16_9:
5060c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 11; // 720p@50Hz
5070c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1280x720p60_16_9:
5080c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 12; // 720p@60Hz
5090c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1920x1080p24_16_9:
5100c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 13; //1080p@24Hz
5110c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1920x1080p25_16_9:
5120c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 14; //108-p@25Hz
5130c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1920x1080p30_16_9:
5140c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 15; //1080p@30Hz
5150c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1920x1080p50_16_9:
5160c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 16; //1080p@50Hz
5170c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        case m1920x1080p60_16_9:
5180c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            return 17; //1080p@60Hz
51972cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed    }
5200c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
5210c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
522f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R/// Returns the user mode set(if any) using adb shell
523f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.Rint ExternalDisplay::getUserMode() {
524f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    /* Based on the property set the resolution */
525f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    char property_value[PROPERTY_VALUE_MAX];
526474d24afc2f7702a8341a622f8877a2631a9ae28Arun Kumar K.R    property_get("hw.hdmi.resolution", property_value, "-1");
527f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    int mode = atoi(property_value);
528f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    // We dont support interlaced modes
529f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    if(isValidMode(mode) && !isInterlacedMode(mode)) {
530da429776b96f9e81aee0b250ab3c0fb9cdcd3254Naseer Ahmed        ALOGD_IF(DEBUG, "%s: setting the HDMI mode = %d", __FUNCTION__, mode);
531f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        return mode;
532f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    }
533f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    return -1;
534f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R}
535f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R
5360c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed// Get the best mode for the current HD TV
53772cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmedint ExternalDisplay::getBestMode() {
5380c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int bestOrder = 0;
5390c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    int bestMode = m640x480p60_4_3;
54056f610dd235b577725198e9341caae92379fdf23Saurabh Shah    Mutex::Autolock lock(mExtDispLock);
5410c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    // for all the edid read, get the best mode
5420c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    for(int i = 0; i < mModeCount; i++) {
5430c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        int mode = mEDIDModes[i];
5440c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        int order = getModeOrder(mode);
5450c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        if (order > bestOrder) {
5460c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            bestOrder = order;
5470c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            bestMode = mode;
5480c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        }
5490c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    }
5500c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    return bestMode;
55172cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed}
5520c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
55372cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmedinline bool ExternalDisplay::isValidMode(int ID)
5540c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
555f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    bool valid = false;
556f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    for (int i = 0; i < mModeCount; i++) {
557f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        if(ID == mEDIDModes[i]) {
558f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R            valid = true;
559f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R            break;
560f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        }
561f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    }
562f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    return valid;
563f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R}
564f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R
565f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R// returns true if the mode(ID) is interlaced mode format
566f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.Rbool ExternalDisplay::isInterlacedMode(int ID) {
567f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    bool interlaced = false;
568f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    switch(ID) {
569f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        case m1440x480i60_4_3:
570f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        case m1440x480i60_16_9:
571f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        case m1440x576i50_4_3:
572f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        case m1440x576i50_16_9:
573f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        case m1920x1080i60_16_9:
574f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R            interlaced = true;
575f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R        default:
576f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R            interlaced = false;
577f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    }
578f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    return interlaced;
5790c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
5800c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
58172cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmedvoid ExternalDisplay::setResolution(int ID)
5820c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
5830c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    struct fb_var_screeninfo info;
584f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    int ret = 0;
585f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
586f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    if(ret < 0) {
587f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
588f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed                                                            strerror(errno));
589f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    }
590f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed
591f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    ALOGD_IF(DEBUG, "%s: GET Info<ID=%d %dx%d (%d,%d,%d),"
592f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed            "(%d,%d,%d) %dMHz>", __FUNCTION__,
593f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed            mVInfo.reserved[3], mVInfo.xres, mVInfo.yres,
594f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed            mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
595f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed            mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
596f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed            mVInfo.pixclock/1000/1000);
597f402f149587c185267504f6eec780eb3fe010a55Arun Kumar K.R    //If its a new ID - update var_screeninfo
598f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    if ((isValidMode(ID)) && mCurrentMode != ID) {
5990c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        const struct disp_mode_timing_type *mode =
60072cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed            &supported_video_mode_lut[0];
6010c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        unsigned count =  sizeof(supported_video_mode_lut)/sizeof
60272cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed            (*supported_video_mode_lut);
6030c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        for (unsigned int i = 0; i < count; ++i) {
6040c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            const struct disp_mode_timing_type *cur =
60572cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed                &supported_video_mode_lut[i];
6060c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            if (cur->video_format == ID)
6070c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed                mode = cur;
6080c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        }
609f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        mode->set_info(mVInfo);
610f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        ALOGD_IF(DEBUG, "%s: SET Info<ID=%d => Info<ID=%d %dx %d"
61172cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmed                 "(%d,%d,%d), (%d,%d,%d) %dMHz>", __FUNCTION__, ID,
6120b2c5624da64ee104dd03eca841e8e5c78e53af6Arun Kumar K.R                 mode->video_format, mVInfo.xres, mVInfo.yres,
613f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed                 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
614f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed                 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
615f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed                 mVInfo.pixclock/1000/1000);
6162310d4e7739b173b950a89c604c553e3302349f5Ken Zhang#ifdef FB_METADATA_VIDEO_INFO_CODE_SUPPORT
6172310d4e7739b173b950a89c604c553e3302349f5Ken Zhang        struct msmfb_metadata metadata;
6182310d4e7739b173b950a89c604c553e3302349f5Ken Zhang        memset(&metadata, 0 , sizeof(metadata));
6192310d4e7739b173b950a89c604c553e3302349f5Ken Zhang        metadata.op = metadata_op_vic;
6202310d4e7739b173b950a89c604c553e3302349f5Ken Zhang        metadata.data.video_info_code = mode->video_format;
6212310d4e7739b173b950a89c604c553e3302349f5Ken Zhang        if (ioctl(mFd, MSMFB_METADATA_SET, &metadata) == -1) {
6222310d4e7739b173b950a89c604c553e3302349f5Ken Zhang            ALOGD("In %s: MSMFB_METADATA_SET failed Err Str = %s",
6232310d4e7739b173b950a89c604c553e3302349f5Ken Zhang                                                 __FUNCTION__, strerror(errno));
6242310d4e7739b173b950a89c604c553e3302349f5Ken Zhang        }
6252310d4e7739b173b950a89c604c553e3302349f5Ken Zhang#endif
6260b2c5624da64ee104dd03eca841e8e5c78e53af6Arun Kumar K.R        mVInfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE;
6270b2c5624da64ee104dd03eca841e8e5c78e53af6Arun Kumar K.R        ret = ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo);
6280b2c5624da64ee104dd03eca841e8e5c78e53af6Arun Kumar K.R        if(ret < 0) {
6290b2c5624da64ee104dd03eca841e8e5c78e53af6Arun Kumar K.R            ALOGD("In %s: FBIOPUT_VSCREENINFO failed Err Str = %s",
6300b2c5624da64ee104dd03eca841e8e5c78e53af6Arun Kumar K.R                                                 __FUNCTION__, strerror(errno));
6310b2c5624da64ee104dd03eca841e8e5c78e53af6Arun Kumar K.R        }
632f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed        mCurrentMode = ID;
6330c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    }
6340c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
6350c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
636c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarvoid ExternalDisplay::setExternalDisplay(bool connected, int extFbNum)
6370c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
6380c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    hwc_context_t* ctx = mHwcContext;
6390c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    if(ctx) {
640c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        ALOGD_IF(DEBUG, "%s: connected = %d", __FUNCTION__, connected);
6410c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        // Store the external display
642c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        mConnected = connected;
643c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        mConnectedFbNum = extFbNum;
6443a85d3e5b8f689cb3a3ef7ef1ce50c1e01afae1aAmara Venkata Mastan Manoj Kumar        mHwcContext->dpyAttr[mExtDpyNum].connected = connected;
645c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        // Update external fb number in Overlay context
646c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        overlay::Overlay::getInstance()->setExtFbNum(extFbNum);
6470c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    }
648c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar}
649c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
650c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarint ExternalDisplay::getExtFbNum(int &fbNum) {
651c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    int ret = -1;
652c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(mConnected) {
653c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        fbNum = mConnectedFbNum;
654c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        ret = 0;
655c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }
656c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    return ret;
6570c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
6580c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed
65972cf9762f84aab07faab86e35fe830b63ec54d72Naseer Ahmedbool ExternalDisplay::writeHPDOption(int userOption) const
6600c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed{
6610c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    bool ret = true;
662c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    char sysFsHPDFilePath[255];
663c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    sprintf(sysFsHPDFilePath ,"/sys/devices/virtual/graphics/fb%d/hpd",
664c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                                mHdmiFbNum);
665c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    int hdmiHPDFile = open(sysFsHPDFilePath,O_RDWR, 0);
6660c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    if (hdmiHPDFile < 0) {
667c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        ALOGE("%s: state file '%s' not found : ret%d err str: %s", __FUNCTION__,
668c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                                sysFsHPDFilePath, hdmiHPDFile, strerror(errno));
6690c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        ret = false;
6700c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    } else {
6710c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        int err = -1;
672c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        ALOGD_IF(DEBUG, "%s: option = %d", __FUNCTION__, userOption);
6730c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        if(userOption)
6740c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            err = write(hdmiHPDFile, "1", 2);
6750c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        else
6760c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            err = write(hdmiHPDFile, "0" , 2);
6770c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        if (err <= 0) {
678c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar            ALOGE("%s: file write failed '%s'", __FUNCTION__, sysFsHPDFilePath);
6790c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed            ret = false;
6800c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        }
6810c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed        close(hdmiHPDFile);
6820c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    }
6830c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed    return ret;
6840c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed}
685f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed
686c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarvoid ExternalDisplay::setDpyWfdAttr() {
687c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    if(mHwcContext) {
6883a85d3e5b8f689cb3a3ef7ef1ce50c1e01afae1aAmara Venkata Mastan Manoj Kumar        mHwcContext->dpyAttr[mExtDpyNum].xres = mVInfo.xres;
6893a85d3e5b8f689cb3a3ef7ef1ce50c1e01afae1aAmara Venkata Mastan Manoj Kumar        mHwcContext->dpyAttr[mExtDpyNum].yres = mVInfo.yres;
6903a85d3e5b8f689cb3a3ef7ef1ce50c1e01afae1aAmara Venkata Mastan Manoj Kumar        mHwcContext->dpyAttr[mExtDpyNum].vsync_period =
691c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar                1000000000l /60;
692c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar        ALOGD_IF(DEBUG,"%s: wfd...connected..!",__FUNCTION__);
693c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar    }
694c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar}
695c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumar
696c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarvoid ExternalDisplay::setDpyHdmiAttr() {
6973e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah    int width = 0, height = 0, fps = 0;
6983e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah    getAttrForMode(width, height, fps);
6993e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah    if(mHwcContext) {
700c4d034f4b8d12953632907d30c0b78856d829579Saurabh Shah        ALOGD("ExtDisplay setting xres = %d, yres = %d", width, height);
7013e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = width;
7023e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = height;
703c4d034f4b8d12953632907d30c0b78856d829579Saurabh Shah        mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period =
704c4d034f4b8d12953632907d30c0b78856d829579Saurabh Shah            1000000000l / fps;
7053e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah    }
7063e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah}
7073e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah
708c9ef1b45b51f4b541da4337cd86dc510654c390bAmara Venkata Mastan Manoj Kumarvoid ExternalDisplay::getAttrForMode(int& width, int& height, int& fps) {
7093e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah    switch (mCurrentMode) {
7103e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m640x480p60_4_3:
7113e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 640;
7123e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 480;
7133e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 60;
7143e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
7153e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m720x480p60_4_3:
7163e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m720x480p60_16_9:
7173e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 720;
7183e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 480;
7193e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 60;
7203e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
7213e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m720x576p50_4_3:
7223e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m720x576p50_16_9:
7233e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 720;
7243e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 576;
7253e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 50;
7263e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
7273e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m1280x720p50_16_9:
7283e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 1280;
7293e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 720;
7303e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 50;
7313e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
7323e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m1280x720p60_16_9:
7333e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 1280;
7343e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 720;
7353e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 60;
7363e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
7373e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m1920x1080p24_16_9:
7383e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 1920;
7393e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 1080;
7403e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 24;
7413e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
7423e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m1920x1080p25_16_9:
7433e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 1920;
7443e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 1080;
7453e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 25;
7463e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
7473e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m1920x1080p30_16_9:
7483e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 1920;
7493e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 1080;
7503e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 30;
7513e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
7523e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m1920x1080p50_16_9:
7533e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 1920;
7543e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 1080;
7553e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 50;
7563e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
7573e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah        case m1920x1080p60_16_9:
7583e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            width = 1920;
7593e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            height = 1080;
7603e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            fps = 60;
7613e858ebde3f2b4e762af8f7f2808d45ba59b890dSaurabh Shah            break;
762f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed    }
763f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed}
764f8ec162999478a3f96dd945831f7c2913a4d3cffNaseer Ahmed
7650c8b7b5c841a7fad5df11b7e02d7cd792cfcc734Naseer Ahmed};
766