Home | History | Annotate | Download | only in recovery
      1 /*
      2  * Copyright (C) 2011 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #include <errno.h>
     18 #include <fcntl.h>
     19 #include <linux/fb.h>
     20 #include <pthread.h>
     21 #include <stdarg.h>
     22 #include <stdio.h>
     23 #include <stdlib.h>
     24 #include <string.h>
     25 #include <sys/ioctl.h>
     26 #include <sys/time.h>
     27 #include <sys/types.h>
     28 #include <time.h>
     29 #include <unistd.h>
     30 
     31 #include <string>
     32 
     33 #include "common.h"
     34 #include "device.h"
     35 #include "ui.h"
     36 #include "screen_ui.h"
     37 
     38 #define kFBDevice "/dev/graphics/fb0"
     39 
     40 #define FBIO_PSB_SET_RGBX       _IOWR('F', 0x42, struct fb_var_screeninfo)
     41 #define FBIO_PSB_SET_RMODE      _IOWR('F', 0x43, struct fb_var_screeninfo)
     42 
     43 class FuguUI : public ScreenRecoveryUI {
     44   public:
     45     bool Init(const std::string& locale) override {
     46         SetupDisplayMode();
     47         return ScreenRecoveryUI::Init(locale);
     48     }
     49 
     50     void SetupDisplayMode() {
     51         printf("opening fb %s\n", kFBDevice);
     52         int fb_dev = open(kFBDevice, O_RDWR);
     53         if (fb_dev == -1) {
     54             fprintf(stderr, "FAIL: failed to open \"%s\": %s\n", kFBDevice, strerror(errno));
     55             return;
     56         }
     57 
     58         struct fb_var_screeninfo current_mode;
     59         if (ioctl(fb_dev, FBIO_PSB_SET_RMODE, &current_mode) == -1) {
     60             fprintf(stderr, "FAIL: unable to set RGBX mode on display controller: %s\n",
     61                     strerror(errno));
     62             return;
     63         }
     64 
     65         if (ioctl(fb_dev, FBIOGET_VSCREENINFO, &current_mode) == -1) {
     66             fprintf(stderr, "FAIL: unable to get mode: %s\n", strerror(errno));
     67             return;
     68         }
     69 
     70         if (ioctl(fb_dev, FBIOBLANK, FB_BLANK_POWERDOWN) == -1) {
     71             fprintf(stderr, "FAIL: unable to blank display: %s\n", strerror(errno));
     72             return;
     73         }
     74 
     75         current_mode.bits_per_pixel = 32;
     76         current_mode.red.offset = 0;
     77         current_mode.red.length = 8;
     78         current_mode.green.offset = 8;
     79         current_mode.green.length = 8;
     80         current_mode.blue.offset = 16;
     81         current_mode.blue.length = 8;
     82 
     83         if (ioctl(fb_dev, FBIOPUT_VSCREENINFO, &current_mode) == -1) {
     84             fprintf(stderr, "FAIL: unable to set mode: %s\n", strerror(errno));
     85             return;
     86         }
     87 
     88         if (ioctl(fb_dev, FBIO_PSB_SET_RGBX, &current_mode) == -1) {
     89             fprintf(stderr, "FAIL: unable to set RGBX mode on display controller: %s\n",
     90                     strerror(errno));
     91             return;
     92         }
     93 
     94         if (ioctl(fb_dev, FBIOBLANK, FB_BLANK_UNBLANK) == -1) {
     95             fprintf(stderr, "FAIL: unable to unblank display: %s\n", strerror(errno));
     96             return;
     97         }
     98     }
     99 };
    100 
    101 Device* make_device() {
    102     return new Device(new FuguUI);
    103 }
    104