189c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos/* 289c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * Copyright (C) 2011 The Android Open Source Project 389c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * 489c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * Licensed under the Apache License, Version 2.0 (the "License"); 589c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * you may not use this file except in compliance with the License. 689c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * You may obtain a copy of the License at 789c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * 889c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * http://www.apache.org/licenses/LICENSE-2.0 989c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * 1089c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * Unless required by applicable law or agreed to in writing, software 1189c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * distributed under the License is distributed on an "AS IS" BASIS, 1289c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1389c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * See the License for the specific language governing permissions and 1489c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos * limitations under the License. 1589c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos */ 1689c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos 173f15f5a7ab6bfcd8fcb189b05916d6ee2e183c44Elliott Hughes#include <errno.h> 1889c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <fcntl.h> 1989c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <linux/fb.h> 2089c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <pthread.h> 2189c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <stdarg.h> 2289c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <stdio.h> 2389c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <stdlib.h> 24c532197b36d722d8307cdc6057b918c729bdba15Elliott Hughes#include <string.h> 2589c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <sys/ioctl.h> 2689c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <sys/time.h> 2789c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <sys/types.h> 2889c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <time.h> 2989c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include <unistd.h> 3089c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos 31ed3c5b4dbbcea41308bbad8af757582a1801c9e4Tao Bao#include <string> 32ed3c5b4dbbcea41308bbad8af757582a1801c9e4Tao Bao 3389c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include "common.h" 3489c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include "device.h" 3589c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include "ui.h" 3689c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#include "screen_ui.h" 3789c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos 3889c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos#define kFBDevice "/dev/graphics/fb0" 39deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes 4052bda14ce8914fbdba7aace07d26f414006ed692Jim Bish#define FBIO_PSB_SET_RGBX _IOWR('F', 0x42, struct fb_var_screeninfo) 4152bda14ce8914fbdba7aace07d26f414006ed692Jim Bish#define FBIO_PSB_SET_RMODE _IOWR('F', 0x43, struct fb_var_screeninfo) 4289c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos 4389c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenosclass FuguUI : public ScreenRecoveryUI { 44deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes public: 45ed3c5b4dbbcea41308bbad8af757582a1801c9e4Tao Bao bool Init(const std::string& locale) override { 4649c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson SetupDisplayMode(); 47ed3c5b4dbbcea41308bbad8af757582a1801c9e4Tao Bao return ScreenRecoveryUI::Init(locale); 4849c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson } 4949c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson 5049c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson void SetupDisplayMode() { 5149c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson printf("opening fb %s\n", kFBDevice); 52deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes int fb_dev = open(kFBDevice, O_RDWR); 53deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes if (fb_dev == -1) { 54deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes fprintf(stderr, "FAIL: failed to open \"%s\": %s\n", kFBDevice, strerror(errno)); 5549c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson return; 5649c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson } 5749c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson 5849c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson struct fb_var_screeninfo current_mode; 59deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes if (ioctl(fb_dev, FBIO_PSB_SET_RMODE, ¤t_mode) == -1) { 60deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes fprintf(stderr, "FAIL: unable to set RGBX mode on display controller: %s\n", 61deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes strerror(errno)); 6252bda14ce8914fbdba7aace07d26f414006ed692Jim Bish return; 6352bda14ce8914fbdba7aace07d26f414006ed692Jim Bish } 6452bda14ce8914fbdba7aace07d26f414006ed692Jim Bish 65deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes if (ioctl(fb_dev, FBIOGET_VSCREENINFO, ¤t_mode) == -1) { 66deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes fprintf(stderr, "FAIL: unable to get mode: %s\n", strerror(errno)); 6749c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson return; 6849c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson } 6949c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson 70deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes if (ioctl(fb_dev, FBIOBLANK, FB_BLANK_POWERDOWN) == -1) { 71deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes fprintf(stderr, "FAIL: unable to blank display: %s\n", strerror(errno)); 7249c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson return; 7349c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson } 7449c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson 7549c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson current_mode.bits_per_pixel = 32; 7649c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson current_mode.red.offset = 0; 7749c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson current_mode.red.length = 8; 7849c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson current_mode.green.offset = 8; 7949c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson current_mode.green.length = 8; 8049c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson current_mode.blue.offset = 16; 8149c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson current_mode.blue.length = 8; 8249c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson 83deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes if (ioctl(fb_dev, FBIOPUT_VSCREENINFO, ¤t_mode) == -1) { 84deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes fprintf(stderr, "FAIL: unable to set mode: %s\n", strerror(errno)); 8549c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson return; 8649c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson } 8749c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson 88deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes if (ioctl(fb_dev, FBIO_PSB_SET_RGBX, ¤t_mode) == -1) { 89deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes fprintf(stderr, "FAIL: unable to set RGBX mode on display controller: %s\n", 90deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes strerror(errno)); 9149c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson return; 9249c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson } 9349c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson 94deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes if (ioctl(fb_dev, FBIOBLANK, FB_BLANK_UNBLANK) == -1) { 95deaaf79a745176e24a12b55cbf0f5e74948e10dfElliott Hughes fprintf(stderr, "FAIL: unable to unblank display: %s\n", strerror(errno)); 9649c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson return; 9749c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson } 9849c0d752dccf96e95c4766c15765ab3fd35778f9Dale Stimson } 9989c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos}; 10089c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos 10189c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenosDevice* make_device() { 102cd586ddf4305ff1976d494477e96850c9c2d3099Elliott Hughes return new Device(new FuguUI); 10389c83d1a6f8a95121f28c3f6c10ef9208aa5923emarie cecile afantenos} 104