summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/android/dx50/lcd-dx50.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/android/dx50/lcd-dx50.c')
-rw-r--r--firmware/target/hosted/android/dx50/lcd-dx50.c120
1 files changed, 120 insertions, 0 deletions
diff --git a/firmware/target/hosted/android/dx50/lcd-dx50.c b/firmware/target/hosted/android/dx50/lcd-dx50.c
new file mode 100644
index 0000000000..4d78baaf00
--- /dev/null
+++ b/firmware/target/hosted/android/dx50/lcd-dx50.c
@@ -0,0 +1,120 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id: lcd-bitmap.c 29248 2011-02-08 20:05:25Z thomasjfox $
9 *
10 * Copyright (C) 2011 Lorenzo Miori, Thomas Martitz
11 * Copyright (C) 2013 Lorenzo Miori
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22
23#include <stdlib.h>
24#include <unistd.h>
25#include <stdio.h>
26#include <linux/fb.h>
27#include <sys/mman.h>
28#include <sys/ioctl.h>
29#include "config.h"
30#include "file.h"
31#include "debug.h"
32#include "system.h"
33#include "screendump.h"
34#include "lcd.h"
35#include "lcd-target.h"
36
37static int dev_fd = 0;
38fb_data *dev_fb = 0;
39
40#ifdef HAVE_LCD_SHUTDOWN
41void lcd_shutdown(void)
42{
43 printf("FB closed.");
44 munmap(dev_fb, FRAMEBUFFER_SIZE);
45 close(dev_fd);
46}
47#endif
48
49void lcd_init_device(void)
50{
51 size_t screensize;
52 struct fb_var_screeninfo vinfo;
53 struct fb_fix_screeninfo finfo;
54
55 /* Open the framebuffer device */
56 dev_fd = open("/dev/graphics/fb0", O_RDWR);
57 if (dev_fd == -1) {
58 perror("Error: cannot open framebuffer device");
59 exit(1);
60 }
61
62 /* Get the fixed properties */
63 if (ioctl(dev_fd, FBIOGET_FSCREENINFO, &finfo) == -1) {
64 perror("Error reading fixed information");
65 exit(2);
66 }
67
68
69 /* Now we get the settable settings, and we set 16 bit bpp */
70 if (ioctl(dev_fd, FBIOGET_VSCREENINFO, &vinfo) == -1) {
71 perror("Error reading variable information");
72 exit(3);
73 }
74 /* framebuffer does not fit the screen, a bug of iBassos Firmware, not rockbox.
75 cannot be solved with parameters */
76 vinfo.bits_per_pixel = LCD_DEPTH;
77 vinfo.xres = vinfo.xres_virtual = vinfo.width = LCD_WIDTH;
78 vinfo.yres = vinfo.yres_virtual = vinfo.height = LCD_HEIGHT;
79
80 if (ioctl(dev_fd, FBIOPUT_VSCREENINFO, &vinfo)) {
81 perror("fbset(ioctl)");
82 exit(4);
83 }
84
85 /* Figure out the size of the screen in bytes */
86 screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
87 if (screensize != FRAMEBUFFER_SIZE) {
88 exit(4);
89 perror("Display and framebuffer mismatch!\n");
90 }
91
92 /* Map the device to memory */
93 dev_fb = mmap(0, screensize, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0);
94 if ((int)dev_fb == -1) {
95 perror("Error: failed to map framebuffer device to memory");
96 exit(4);
97 }
98
99 /* Be sure to turn on display at startup */
100 ioctl(dev_fd, FBIOBLANK, VESA_NO_BLANKING);
101#ifdef HAVE_LCD_ENABLE
102 lcd_set_active(true);
103#endif
104}
105
106#ifdef HAVE_LCD_ENABLE
107void lcd_enable(bool enable)
108 {
109 if (lcd_active() == enable)
110 return;
111
112 lcd_set_active(enable);
113
114 /* Turn on or off the display using Linux interface */
115 ioctl(dev_fd, FBIOBLANK, enable ? VESA_NO_BLANKING : VESA_POWERDOWN);
116
117 if (enable)
118 send_event(LCD_EVENT_ACTIVATION, NULL);
119}
120#endif