blob: b9abc31b851d33d377ef5399f5209d7c416d65e7 [file] [log] [blame]
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
Saurabh Shah56f610d2012-08-07 15:27:06 -07003 * Copyright (C) 2012, The Linux Foundation. All rights reserved.
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -07004 *
5 * Not a Contribution, Apache license notifications and license are
6 * retained for attribution purposes only.
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20
Naseer Ahmed72cf9762012-07-21 12:17:13 -070021#define DEBUG 0
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070022#include <ctype.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070023#include <fcntl.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070024#include <media/IAudioPolicyService.h>
25#include <media/AudioSystem.h>
26#include <utils/threads.h>
27#include <utils/Errors.h>
28#include <utils/Log.h>
29
30#include <linux/msm_mdp.h>
31#include <linux/fb.h>
32#include <sys/ioctl.h>
33#include <sys/poll.h>
Naseer Ahmed72cf9762012-07-21 12:17:13 -070034#include <sys/resource.h>
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070035#include <cutils/properties.h>
36#include "hwc_utils.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070037#include "external.h"
38#include "overlayUtils.h"
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080039#include "overlay.h"
Saurabh Shah56f610d2012-08-07 15:27:06 -070040
41using namespace android;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070042
43namespace qhwc {
44
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080045#define MAX_FRAME_BUFFER_NAME_SIZE (80)
46#define MAX_DISPLAY_DEVICES (3)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070047
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070048
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080049const char* msmFbDevicePath[] = { "/dev/graphics/fb1",
50 "/dev/graphics/fb2"};
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -070051
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -080052/*
53 * Updates extDeviceFbIndex Array with the correct frame buffer indices
54 * of avaiable external devices
55 *
56 */
57void ExternalDisplay::updateExtDispDevFbIndex()
58{
59 FILE *displayDeviceFP = NULL;
60 char fbType[MAX_FRAME_BUFFER_NAME_SIZE];
61 char msmFbTypePath[MAX_FRAME_BUFFER_NAME_SIZE];
62
63 for(int j = 1; j < MAX_DISPLAY_DEVICES; j++) {
64 sprintf (msmFbTypePath,"/sys/class/graphics/fb%d/msm_fb_type", j);
65 displayDeviceFP = fopen(msmFbTypePath, "r");
66 if(displayDeviceFP){
67 fread(fbType, sizeof(char), MAX_FRAME_BUFFER_NAME_SIZE,
68 displayDeviceFP);
69 if(strncmp(fbType, "dtv panel", strlen("dtv panel")) == 0){
70 ALOGD_IF(DEBUG,"hdmi framebuffer index is %d",j);
71 mHdmiFbNum = j;
72 } else if(strncmp(fbType, "writeback panel",
73 strlen("writeback panel")) == 0){
74 ALOGD_IF(DEBUG,"wfd framebuffer index is %d",j);
75 mWfdFbNum = j;
76 }
77 fclose(displayDeviceFP);
78 }
79 }
80 ALOGD_IF(DEBUG,"%s: mHdmiFbNum: %d mWfdFbNum: %d ",__FUNCTION__,
81 mHdmiFbNum, mWfdFbNum);
82}
83
84int ExternalDisplay::configureHDMIDisplay() {
85 openFrameBuffer(mHdmiFbNum);
86 if(mFd == -1)
87 return -1;
88 readResolution();
89 //Get the best mode and set
90 // TODO: Move this to activate
91 setResolution(getBestMode());
92 setDpyHdmiAttr();
93 setExternalDisplay(true, mHdmiFbNum);
94 return 0;
95}
96
97int ExternalDisplay::configureWFDDisplay() {
98 int ret = 0;
99 if(mConnectedFbNum == mHdmiFbNum) {
100 ALOGE("%s: Cannot process WFD connection while HDMI is active",
101 __FUNCTION__);
102 return -1;
103 }
104 openFrameBuffer(mWfdFbNum);
105 if(mFd == -1)
106 return -1;
107 ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
108 if(ret < 0) {
109 ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
110 strerror(errno));
111 }
112 setDpyWfdAttr();
113 setExternalDisplay(true, mWfdFbNum);
114 return 0;
115}
116
117int ExternalDisplay::teardownHDMIDisplay() {
118 if(mConnectedFbNum == mHdmiFbNum) {
119 // hdmi offline event..!
120 closeFrameBuffer();
121 resetInfo();
122 setExternalDisplay(false);
123 }
124 return 0;
125}
126
127int ExternalDisplay::teardownWFDDisplay() {
128 if(mConnectedFbNum == mWfdFbNum) {
129 // wfd offline event..!
130 closeFrameBuffer();
131 memset(&mVInfo, 0, sizeof(mVInfo));
132 setExternalDisplay(false);
133 }
134 return 0;
135}
136
137void ExternalDisplay::processUEventOnline(const char *str) {
138 const char *s1 = str + strlen("change@/devices/virtual/switch/");
139 if(!strncmp(s1,"hdmi",strlen(s1))) {
140 // hdmi online event..!
141 configureHDMIDisplay();
142 }else if(!strncmp(s1,"wfd",strlen(s1))) {
143 // wfd online event..!
144 configureWFDDisplay();
145 }
146}
147
148void ExternalDisplay::processUEventOffline(const char *str) {
149 const char *s1 = str + strlen("change@/devices/virtual/switch/");
150 if(!strncmp(s1,"hdmi",strlen(s1))) {
151 teardownHDMIDisplay();
152 }else if(!strncmp(s1,"wfd",strlen(s1))) {
153 teardownWFDDisplay();
154 }
155}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700156
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700157ExternalDisplay::ExternalDisplay(hwc_context_t* ctx):mFd(-1),
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800158 mCurrentMode(-1), mConnected(0), mConnectedFbNum(0), mModeCount(0),
159 mHwcContext(ctx), mHdmiFbNum(-1), mWfdFbNum(-1)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700160{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700161 memset(&mVInfo, 0, sizeof(mVInfo));
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800162 //Determine the fb index for external display devices.
163 updateExtDispDevFbIndex();
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700164}
165
Saurabh Shah56f610d2012-08-07 15:27:06 -0700166void ExternalDisplay::setEDIDMode(int resMode) {
167 ALOGD_IF(DEBUG,"resMode=%d ", resMode);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700168 {
169 Mutex::Autolock lock(mExtDispLock);
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800170 setExternalDisplay(false);
171 openFrameBuffer(mHdmiFbNum);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700172 setResolution(resMode);
173 }
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800174 setExternalDisplay(true, mHdmiFbNum);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700175}
176
177void ExternalDisplay::setHPD(uint32_t startEnd) {
178 ALOGD_IF(DEBUG,"HPD enabled=%d", startEnd);
179 writeHPDOption(startEnd);
180}
181
182void ExternalDisplay::setActionSafeDimension(int w, int h) {
183 ALOGD_IF(DEBUG,"ActionSafe w=%d h=%d", w, h);
184 Mutex::Autolock lock(mExtDispLock);
185 overlay::utils::ActionSafe::getInstance()->setDimension(w, h);
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800186 setExternalDisplay(true, mHdmiFbNum);
Saurabh Shah56f610d2012-08-07 15:27:06 -0700187}
188
189int ExternalDisplay::getModeCount() const {
190 ALOGD_IF(DEBUG,"HPD mModeCount=%d", mModeCount);
191 Mutex::Autolock lock(mExtDispLock);
192 return mModeCount;
193}
194
195void ExternalDisplay::getEDIDModes(int *out) const {
196 Mutex::Autolock lock(mExtDispLock);
197 for(int i = 0;i < mModeCount;i++) {
198 out[i] = mEDIDModes[i];
199 }
200}
201
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700202ExternalDisplay::~ExternalDisplay()
203{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700204 closeFrameBuffer();
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700205}
206
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700207struct disp_mode_timing_type {
208 int video_format;
209
210 int active_h;
211 int active_v;
212
213 int front_porch_h;
214 int pulse_width_h;
215 int back_porch_h;
216
217 int front_porch_v;
218 int pulse_width_v;
219 int back_porch_v;
220
221 int pixel_freq;
222 bool interlaced;
223
224 void set_info(struct fb_var_screeninfo &info) const;
225};
226
227void disp_mode_timing_type::set_info(struct fb_var_screeninfo &info) const
228{
229 info.reserved[0] = 0;
230 info.reserved[1] = 0;
231 info.reserved[2] = 0;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700232 info.reserved[3] = (info.reserved[3] & 0xFFFF) | (video_format << 16);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700233
234 info.xoffset = 0;
235 info.yoffset = 0;
236 info.xres = active_h;
237 info.yres = active_v;
238
239 info.pixclock = pixel_freq*1000;
240 info.vmode = interlaced ? FB_VMODE_INTERLACED : FB_VMODE_NONINTERLACED;
241
242 info.right_margin = front_porch_h;
243 info.hsync_len = pulse_width_h;
244 info.left_margin = back_porch_h;
245 info.lower_margin = front_porch_v;
246 info.vsync_len = pulse_width_v;
247 info.upper_margin = back_porch_v;
248}
249
250/* Video formates supported by the HDMI Standard */
251/* Indicates the resolution, pix clock and the aspect ratio */
252#define m640x480p60_4_3 1
253#define m720x480p60_4_3 2
254#define m720x480p60_16_9 3
255#define m1280x720p60_16_9 4
256#define m1920x1080i60_16_9 5
257#define m1440x480i60_4_3 6
258#define m1440x480i60_16_9 7
259#define m1920x1080p60_16_9 16
260#define m720x576p50_4_3 17
261#define m720x576p50_16_9 18
262#define m1280x720p50_16_9 19
263#define m1440x576i50_4_3 21
264#define m1440x576i50_16_9 22
265#define m1920x1080p50_16_9 31
266#define m1920x1080p24_16_9 32
267#define m1920x1080p25_16_9 33
268#define m1920x1080p30_16_9 34
269
270static struct disp_mode_timing_type supported_video_mode_lut[] = {
271 {m640x480p60_4_3, 640, 480, 16, 96, 48, 10, 2, 33, 25200, false},
272 {m720x480p60_4_3, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false},
273 {m720x480p60_16_9, 720, 480, 16, 62, 60, 9, 6, 30, 27030, false},
274 {m1280x720p60_16_9, 1280, 720, 110, 40, 220, 5, 5, 20, 74250, false},
275 {m1920x1080i60_16_9, 1920, 540, 88, 44, 148, 2, 5, 5, 74250, false},
276 {m1440x480i60_4_3, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true},
277 {m1440x480i60_16_9, 1440, 240, 38, 124, 114, 4, 3, 15, 27000, true},
278 {m1920x1080p60_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 148500, false},
279 {m720x576p50_4_3, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false},
280 {m720x576p50_16_9, 720, 576, 12, 64, 68, 5, 5, 39, 27000, false},
281 {m1280x720p50_16_9, 1280, 720, 440, 40, 220, 5, 5, 20, 74250, false},
282 {m1440x576i50_4_3, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true},
283 {m1440x576i50_16_9, 1440, 288, 24, 126, 138, 2, 3, 19, 27000, true},
284 {m1920x1080p50_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 148500, false},
285 {m1920x1080p24_16_9, 1920, 1080, 638, 44, 148, 4, 5, 36, 74250, false},
286 {m1920x1080p25_16_9, 1920, 1080, 528, 44, 148, 4, 5, 36, 74250, false},
287 {m1920x1080p30_16_9, 1920, 1080, 88, 44, 148, 4, 5, 36, 74250, false},
288};
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700289
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700290int ExternalDisplay::parseResolution(char* edidStr, int* edidModes)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700291{
292 char delim = ',';
293 int count = 0;
294 char *start, *end;
295 // EDIDs are string delimited by ','
296 // Ex: 16,4,5,3,32,34,1
297 // Parse this string to get mode(int)
298 start = (char*) edidStr;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700299 end = &delim;
300 while(*end == delim) {
301 edidModes[count] = (int) strtol(start, &end, 10);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700302 start = end+1;
303 count++;
304 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700305 ALOGD_IF(DEBUG, "In %s: count = %d", __FUNCTION__, count);
306 for (int i = 0; i < count; i++)
307 ALOGD_IF(DEBUG, "Mode[%d] = %d", i, edidModes[i]);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700308 return count;
309}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700310
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700311bool ExternalDisplay::readResolution()
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700312{
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800313 char sysFsEDIDFilePath[255];
314 sprintf(sysFsEDIDFilePath , "/sys/devices/virtual/graphics/fb%d/edid_modes",
315 mHdmiFbNum);
316
317 int hdmiEDIDFile = open(sysFsEDIDFilePath, O_RDONLY, 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700318 int len = -1;
319
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700320 if (hdmiEDIDFile < 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700321 ALOGE("%s: edid_modes file '%s' not found",
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800322 __FUNCTION__, sysFsEDIDFilePath);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700323 return false;
324 } else {
325 len = read(hdmiEDIDFile, mEDIDs, sizeof(mEDIDs)-1);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700326 ALOGD_IF(DEBUG, "%s: EDID string: %s length = %d",
327 __FUNCTION__, mEDIDs, len);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700328 if ( len <= 0) {
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700329 ALOGE("%s: edid_modes file empty '%s'",
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800330 __FUNCTION__, sysFsEDIDFilePath);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700331 }
332 else {
333 while (len > 1 && isspace(mEDIDs[len-1]))
334 --len;
335 mEDIDs[len] = 0;
336 }
337 }
338 close(hdmiEDIDFile);
339 if(len > 0) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800340 // Get EDID modes from the EDID strings
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700341 mModeCount = parseResolution(mEDIDs, mEDIDModes);
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700342 ALOGD_IF(DEBUG, "%s: mModeCount = %d", __FUNCTION__,
343 mModeCount);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700344 }
345
346 return (strlen(mEDIDs) > 0);
347}
348
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800349bool ExternalDisplay::openFrameBuffer(int fbNum)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700350{
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700351 if (mFd == -1) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800352 mFd = open(msmFbDevicePath[fbNum-1], O_RDWR);
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700353 if (mFd < 0)
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800354 ALOGE("%s: %s is not available", __FUNCTION__,
355 msmFbDevicePath[fbNum-1]);
356 if(mHwcContext) {
357 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].fd = mFd;
358 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700359 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700360 return (mFd > 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700361}
362
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700363bool ExternalDisplay::closeFrameBuffer()
364{
365 int ret = 0;
366 if(mFd > 0) {
367 ret = close(mFd);
368 mFd = -1;
369 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700370 if(mHwcContext) {
371 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].fd = mFd;
372 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700373 return (ret == 0);
374}
375
376// clears the vinfo, edid, best modes
377void ExternalDisplay::resetInfo()
378{
379 memset(&mVInfo, 0, sizeof(mVInfo));
380 memset(mEDIDs, 0, sizeof(mEDIDs));
381 memset(mEDIDModes, 0, sizeof(mEDIDModes));
382 mModeCount = 0;
383 mCurrentMode = -1;
384}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700385
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700386int ExternalDisplay::getModeOrder(int mode)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700387{
388 switch (mode) {
389 default:
390 case m1440x480i60_4_3:
391 return 1; // 480i 4:3
392 case m1440x480i60_16_9:
393 return 2; // 480i 16:9
394 case m1440x576i50_4_3:
395 return 3; // i576i 4:3
396 case m1440x576i50_16_9:
397 return 4; // 576i 16:9
398 case m640x480p60_4_3:
399 return 5; // 640x480 4:3
400 case m720x480p60_4_3:
401 return 6; // 480p 4:3
402 case m720x480p60_16_9:
403 return 7; // 480p 16:9
404 case m720x576p50_4_3:
405 return 8; // 576p 4:3
406 case m720x576p50_16_9:
407 return 9; // 576p 16:9
408 case m1920x1080i60_16_9:
409 return 10; // 1080i 16:9
410 case m1280x720p50_16_9:
411 return 11; // 720p@50Hz
412 case m1280x720p60_16_9:
413 return 12; // 720p@60Hz
414 case m1920x1080p24_16_9:
415 return 13; //1080p@24Hz
416 case m1920x1080p25_16_9:
417 return 14; //108-p@25Hz
418 case m1920x1080p30_16_9:
419 return 15; //1080p@30Hz
420 case m1920x1080p50_16_9:
421 return 16; //1080p@50Hz
422 case m1920x1080p60_16_9:
423 return 17; //1080p@60Hz
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700424 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700425}
426
427// Get the best mode for the current HD TV
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700428int ExternalDisplay::getBestMode() {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700429 int bestOrder = 0;
430 int bestMode = m640x480p60_4_3;
Saurabh Shah56f610d2012-08-07 15:27:06 -0700431 Mutex::Autolock lock(mExtDispLock);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700432 // for all the edid read, get the best mode
433 for(int i = 0; i < mModeCount; i++) {
434 int mode = mEDIDModes[i];
435 int order = getModeOrder(mode);
436 if (order > bestOrder) {
437 bestOrder = order;
438 bestMode = mode;
439 }
440 }
441 return bestMode;
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700442}
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700443
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700444inline bool ExternalDisplay::isValidMode(int ID)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700445{
446 return ((ID >= m640x480p60_4_3) && (ID <= m1920x1080p30_16_9));
447}
448
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700449void ExternalDisplay::setResolution(int ID)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700450{
451 struct fb_var_screeninfo info;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700452 int ret = 0;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700453 ret = ioctl(mFd, FBIOGET_VSCREENINFO, &mVInfo);
454 if(ret < 0) {
455 ALOGD("In %s: FBIOGET_VSCREENINFO failed Err Str = %s", __FUNCTION__,
456 strerror(errno));
457 }
458
459 ALOGD_IF(DEBUG, "%s: GET Info<ID=%d %dx%d (%d,%d,%d),"
460 "(%d,%d,%d) %dMHz>", __FUNCTION__,
461 mVInfo.reserved[3], mVInfo.xres, mVInfo.yres,
462 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
463 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
464 mVInfo.pixclock/1000/1000);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700465 //If its a valid mode and its a new ID - update var_screeninfo
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700466 if ((isValidMode(ID)) && mCurrentMode != ID) {
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700467 const struct disp_mode_timing_type *mode =
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700468 &supported_video_mode_lut[0];
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700469 unsigned count = sizeof(supported_video_mode_lut)/sizeof
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700470 (*supported_video_mode_lut);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700471 for (unsigned int i = 0; i < count; ++i) {
472 const struct disp_mode_timing_type *cur =
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700473 &supported_video_mode_lut[i];
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700474 if (cur->video_format == ID)
475 mode = cur;
476 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700477 mode->set_info(mVInfo);
478 ALOGD_IF(DEBUG, "%s: SET Info<ID=%d => Info<ID=%d %dx %d"
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700479 "(%d,%d,%d), (%d,%d,%d) %dMHz>", __FUNCTION__, ID,
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700480 mVInfo.reserved[3], mVInfo.xres, mVInfo.yres,
481 mVInfo.right_margin, mVInfo.hsync_len, mVInfo.left_margin,
482 mVInfo.lower_margin, mVInfo.vsync_len, mVInfo.upper_margin,
483 mVInfo.pixclock/1000/1000);
484 mVInfo.activate = FB_ACTIVATE_NOW | FB_ACTIVATE_ALL | FB_ACTIVATE_FORCE;
485 ret = ioctl(mFd, FBIOPUT_VSCREENINFO, &mVInfo);
486 if(ret < 0) {
487 ALOGD("In %s: FBIOPUT_VSCREENINFO failed Err Str = %s",
488 __FUNCTION__, strerror(errno));
489 }
490 mCurrentMode = ID;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700491 }
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700492}
493
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800494void ExternalDisplay::setExternalDisplay(bool connected, int extFbNum)
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700495{
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700496 hwc_context_t* ctx = mHwcContext;
497 if(ctx) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800498 ALOGD_IF(DEBUG, "%s: connected = %d", __FUNCTION__, connected);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700499 // Store the external display
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800500 mConnected = connected;
501 mConnectedFbNum = extFbNum;
502 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].connected = connected;
503 // Update external fb number in Overlay context
504 overlay::Overlay::getInstance()->setExtFbNum(extFbNum);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700505 }
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800506}
507
508int ExternalDisplay::getExtFbNum(int &fbNum) {
509 int ret = -1;
510 if(mConnected) {
511 fbNum = mConnectedFbNum;
512 ret = 0;
513 }
514 return ret;
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700515}
516
Naseer Ahmed72cf9762012-07-21 12:17:13 -0700517bool ExternalDisplay::writeHPDOption(int userOption) const
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700518{
519 bool ret = true;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800520 char sysFsHPDFilePath[255];
521 sprintf(sysFsHPDFilePath ,"/sys/devices/virtual/graphics/fb%d/hpd",
522 mHdmiFbNum);
523 int hdmiHPDFile = open(sysFsHPDFilePath,O_RDWR, 0);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700524 if (hdmiHPDFile < 0) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800525 ALOGE("%s: state file '%s' not found : ret%d err str: %s", __FUNCTION__,
526 sysFsHPDFilePath, hdmiHPDFile, strerror(errno));
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700527 ret = false;
528 } else {
529 int err = -1;
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800530 ALOGD_IF(DEBUG, "%s: option = %d", __FUNCTION__, userOption);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700531 if(userOption)
532 err = write(hdmiHPDFile, "1", 2);
533 else
534 err = write(hdmiHPDFile, "0" , 2);
535 if (err <= 0) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800536 ALOGE("%s: file write failed '%s'", __FUNCTION__, sysFsHPDFilePath);
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700537 ret = false;
538 }
539 close(hdmiHPDFile);
540 }
541 return ret;
542}
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700543
Saurabh Shah3825f252012-09-21 16:32:18 -0700544/*
545 * commits the changes to the external display
Saurabh Shah3825f252012-09-21 16:32:18 -0700546 */
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700547bool ExternalDisplay::post()
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700548{
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500549 if(mFd == -1)
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700550 return false;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500551 struct mdp_display_commit ext_commit;
Naseer Ahmed9da84662012-12-06 19:29:29 -0500552 memset(&ext_commit, 0, sizeof(struct mdp_display_commit));
553 ext_commit.flags = MDP_DISPLAY_COMMIT_OVERLAY;
Naseer Ahmed54821fe2012-11-28 18:44:38 -0500554 if (ioctl(mFd, MSMFB_DISPLAY_COMMIT, &ext_commit) == -1) {
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800555 ALOGE("%s: MSMFB_DISPLAY_COMMIT for external failed, str: %s",
556 __FUNCTION__, strerror(errno));
557 return false;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700558 }
559 return true;
560}
561
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800562void ExternalDisplay::setDpyWfdAttr() {
563 if(mHwcContext) {
564 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = mVInfo.xres;
565 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = mVInfo.yres;
566 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period =
567 1000000000l /60;
568 ALOGD_IF(DEBUG,"%s: wfd...connected..!",__FUNCTION__);
569 }
570}
571
572void ExternalDisplay::setDpyHdmiAttr() {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700573 int width = 0, height = 0, fps = 0;
574 getAttrForMode(width, height, fps);
575 if(mHwcContext) {
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700576 ALOGD("ExtDisplay setting xres = %d, yres = %d", width, height);
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700577 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].xres = width;
578 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].yres = height;
Saurabh Shahc4d034f2012-09-27 15:55:15 -0700579 mHwcContext->dpyAttr[HWC_DISPLAY_EXTERNAL].vsync_period =
580 1000000000l / fps;
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700581 }
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700582}
583
Amara Venkata Mastan Manoj Kumar5182a782012-12-03 12:08:48 -0800584void ExternalDisplay::getAttrForMode(int& width, int& height, int& fps) {
Saurabh Shah3e858eb2012-09-17 16:53:21 -0700585 switch (mCurrentMode) {
586 case m640x480p60_4_3:
587 width = 640;
588 height = 480;
589 fps = 60;
590 break;
591 case m720x480p60_4_3:
592 case m720x480p60_16_9:
593 width = 720;
594 height = 480;
595 fps = 60;
596 break;
597 case m720x576p50_4_3:
598 case m720x576p50_16_9:
599 width = 720;
600 height = 576;
601 fps = 50;
602 break;
603 case m1280x720p50_16_9:
604 width = 1280;
605 height = 720;
606 fps = 50;
607 break;
608 case m1280x720p60_16_9:
609 width = 1280;
610 height = 720;
611 fps = 60;
612 break;
613 case m1920x1080p24_16_9:
614 width = 1920;
615 height = 1080;
616 fps = 24;
617 break;
618 case m1920x1080p25_16_9:
619 width = 1920;
620 height = 1080;
621 fps = 25;
622 break;
623 case m1920x1080p30_16_9:
624 width = 1920;
625 height = 1080;
626 fps = 30;
627 break;
628 case m1920x1080p50_16_9:
629 width = 1920;
630 height = 1080;
631 fps = 50;
632 break;
633 case m1920x1080p60_16_9:
634 width = 1920;
635 height = 1080;
636 fps = 60;
637 break;
638 }
Naseer Ahmedf8ec1622012-07-31 18:56:23 -0700639}
640
Naseer Ahmed0c8b7b52012-07-20 09:06:13 -0700641};