summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/ibasso/lcd-ibasso.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/hosted/ibasso/lcd-ibasso.c')
-rw-r--r--firmware/target/hosted/ibasso/lcd-ibasso.c195
1 files changed, 195 insertions, 0 deletions
diff --git a/firmware/target/hosted/ibasso/lcd-ibasso.c b/firmware/target/hosted/ibasso/lcd-ibasso.c
new file mode 100644
index 0000000000..4e03ba7e50
--- /dev/null
+++ b/firmware/target/hosted/ibasso/lcd-ibasso.c
@@ -0,0 +1,195 @@
1/***************************************************************************
2 * __________ __ ___
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2014 by Ilia Sergachev: Initial Rockbox port to iBasso DX50
10 * Copyright (C) 2014 by Mario Basister: iBasso DX90 port
11 * Copyright (C) 2014 by Simon Rothen: Initial Rockbox repository submission, additional features
12 * Copyright (C) 2014 by Udo Schläpfer: Code clean up, additional features
13 *
14 * This program is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU General Public License
16 * as published by the Free Software Foundation; either version 2
17 * of the License, or (at your option) any later version.
18 *
19 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
20 * KIND, either express or implied.
21 *
22 ****************************************************************************/
23
24
25#include <errno.h>
26#include <fcntl.h>
27#include <stdbool.h>
28#include <stdlib.h>
29#include <linux/fb.h>
30#include <sys/ioctl.h>
31#include <sys/mman.h>
32#include <sys/stat.h>
33#include <sys/types.h>
34
35#include "config.h"
36#include "debug.h"
37#include "events.h"
38#include "panic.h"
39
40#include "debug-ibasso.h"
41#include "lcd-target.h"
42#include "sysfs-ibasso.h"
43
44
45fb_data *dev_fb = 0;
46
47
48/* Framebuffer device handle. */
49static int dev_fd = 0;
50
51
52void lcd_init_device(void)
53{
54 TRACE;
55
56 dev_fd = open("/dev/graphics/fb0", O_RDWR);
57 if(dev_fd == -1)
58 {
59 DEBUGF("ERROR %s: open failed on /dev/graphics/fb0, errno: %d.", __func__, errno);
60 exit(errno);
61 }
62
63 /* Get the changeable information. */
64 struct fb_var_screeninfo vinfo;
65 if(ioctl(dev_fd, FBIOGET_VSCREENINFO, &vinfo) < 0)
66 {
67 DEBUGF("ERROR %s: ioctl FBIOGET_VSCREENINFO failed on /dev/graphics/fb0, errno: %d.", __func__, errno);
68 exit(errno);
69 }
70
71 DEBUGF("DEBUG %s: bits_per_pixel: %u, width: %u, height: %u.", __func__, vinfo.bits_per_pixel, vinfo.width, vinfo.height);
72
73 /*
74 Framebuffer does not fit the screen, a bug of iBassos Firmware, not Rockbox.
75 Cannot be solved with parameters.
76 */
77 /*vinfo.bits_per_pixel = LCD_DEPTH;
78 vinfo.xres = LCD_WIDTH;
79 vinfo.xres_virtual = LCD_WIDTH;
80 vinfo.width = LCD_WIDTH;
81 vinfo.yres = LCD_HEIGHT;
82 vinfo.yres_virtual = LCD_HEIGHT;
83 vinfo.height = LCD_HEIGHT;
84 vinfo.activate = FB_ACTIVATE_NOW;
85 if(ioctl(dev_fd, FBIOPUT_VSCREENINFO, &vinfo) == -1)
86 {
87 DEBUGF("ERROR %s: ioctl FBIOPUT_VSCREENINFO failed on /dev/graphics/fb0, errno: %d.", __func__, errno);
88 exit(EXIT_FAILURE);
89 }*/
90
91
92 /* Sanity check: Does framebuffer config match Rockbox config? */
93 size_t screensize = vinfo.xres * vinfo.yres * vinfo.bits_per_pixel / 8;
94 if(screensize != FRAMEBUFFER_SIZE)
95 {
96 DEBUGF("ERROR %s: Screen size does not match config: %d != %d.", __func__, screensize, FRAMEBUFFER_SIZE);
97 exit(EXIT_FAILURE);
98 }
99
100 /* Map the device to memory. */
101 dev_fb = mmap(0, FRAMEBUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, 0);
102 if(dev_fb == MAP_FAILED)
103 {
104 DEBUGF("ERROR %s: mmap failed on /dev/graphics/fb0, errno: %d.", __func__, errno);
105 exit(errno);
106 }
107
108 /* Activate Rockbox LCD. */
109 lcd_enable(true);
110}
111
112
113void lcd_shutdown(void)
114{
115 TRACE;
116
117 lcd_set_active(false);
118 munmap(dev_fb, FRAMEBUFFER_SIZE);
119 close(dev_fd) ;
120}
121
122
123/*
124 Left as reference. Unblanking does not work as expected, will not enable LCD after a few
125 seconds of power down.
126 Instead the backlight power is toggled.
127*/
128/*void lcd_power_on(void)
129{
130 TRACE;
131
132 if(ioctl(dev_fd, FBIOBLANK, VESA_NO_BLANKING) == -1)
133 {
134 DEBUGF("ERROR %s: ioctl FBIOBLANK failed on /dev/graphics/fb0, errno: %d.", __func__, errno);
135 panicf("ERROR %s: ioctl FBIOBLANK failed on /dev/graphics/fb0, errno: %d.", __func__, errno);
136 return;
137 }
138
139 lcd_set_active(true);
140 send_event(LCD_EVENT_ACTIVATION, NULL);
141}
142
143
144void lcd_power_off(void)
145{
146 TRACE;
147
148 lcd_set_active(false);
149
150 if(ioctl(dev_fd, FBIOBLANK, VESA_POWERDOWN) == -1)
151 {
152 DEBUGF("ERROR %s: ioctl FBIOBLANK failed on /dev/graphics/fb0, errno: %d.", __func__, errno);
153 panicf("ERROR %s: ioctl FBIOBLANK failed on /dev/graphics/fb0, errno: %d.", __func__, errno);
154 return;
155 }
156}*/
157
158
159void lcd_enable(bool on)
160{
161 TRACE;
162
163 lcd_set_active(on);
164
165 if(on)
166 {
167 /*
168 /sys/power/state
169 on: Cancel suspend.
170 */
171 if(! sysfs_set_string(SYSFS_POWER_STATE, "on"))
172 {
173 DEBUGF("ERROR %s: Can not set power state.", __func__);
174 }
175
176 send_event(LCD_EVENT_ACTIVATION, NULL);
177 }
178}
179
180
181void lcd_sleep(void)
182{
183 TRACE;
184
185 /*
186 See system_init(). Without suspend blocker und mute prevention this will interrupt playback.
187 Essentially, we are turning off the touch screen.
188 /sys/power/state
189 mem: Suspend to RAM.
190 */
191 if(! sysfs_set_string(SYSFS_POWER_STATE, "mem"))
192 {
193 DEBUGF("ERROR %s: Can not set power state.", __func__);
194 }
195}