summaryrefslogtreecommitdiff
path: root/firmware/target/hosted/lcd-linuxfb.c
diff options
context:
space:
mode:
authorSolomon Peachy <pizza@shaftnet.org>2020-04-08 09:53:13 -0400
committerSolomon Peachy <pizza@shaftnet.org>2020-04-08 15:56:06 +0200
commit53b93ea6a60cf8900c88e00f774693dea9a4f297 (patch)
treee4370674e13dc6c1a9d71479707ff8e44c15a0ab /firmware/target/hosted/lcd-linuxfb.c
parent6fcd69a365365ad828410d0c58970e8bef9112b6 (diff)
downloadrockbox-53b93ea6a60cf8900c88e00f774693dea9a4f297.tar.gz
rockbox-53b93ea6a60cf8900c88e00f774693dea9a4f297.zip
hiby: Refactor X3ii/X20 and Rocker LCD code
Once some missing power optimization stuff was added to the X3ii code, they were completely identical. Change-Id: I68e4db5e270e8ff22f91e521616a054bd7baa95d
Diffstat (limited to 'firmware/target/hosted/lcd-linuxfb.c')
-rw-r--r--firmware/target/hosted/lcd-linuxfb.c154
1 files changed, 154 insertions, 0 deletions
diff --git a/firmware/target/hosted/lcd-linuxfb.c b/firmware/target/hosted/lcd-linuxfb.c
new file mode 100644
index 0000000000..6a3aa36b5d
--- /dev/null
+++ b/firmware/target/hosted/lcd-linuxfb.c
@@ -0,0 +1,154 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 *
9 * Copyright (C) 2017 Marcin Bukat
10 * Copyright (C) 2016 Amaury Pouly
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <unistd.h>
24#include <stdio.h>
25#include <linux/fb.h>
26#include <sys/mman.h>
27#include <sys/ioctl.h>
28#include <fcntl.h>
29#include "lcd.h"
30#include "lcd-target.h"
31#include "backlight-target.h"
32#include "sysfs.h"
33#include "panic.h"
34
35static int fd = -1;
36static struct fb_var_screeninfo vinfo;
37fb_data *framebuffer = 0; /* global variable, see lcd-target.h */
38
39void lcd_init_device(void)
40{
41 const char * const fb_dev = "/dev/fb0";
42 fd = open(fb_dev, O_RDWR);
43 if(fd < 0)
44 {
45 panicf("Cannot open framebuffer: %s\n", fb_dev);
46 }
47
48 /* get fixed and variable information */
49 struct fb_fix_screeninfo finfo;
50 if(ioctl(fd, FBIOGET_FSCREENINFO, &finfo) < 0)
51 {
52 panicf("Cannot read framebuffer fixed information");
53 }
54
55 if(ioctl(fd, FBIOGET_VSCREENINFO, &vinfo) < 0)
56 {
57 panicf("Cannot read framebuffer variable information");
58 }
59
60#if 0
61 /* check resolution and framebuffer size */
62 if(vinfo.xres != LCD_WIDTH || vinfo.yres != LCD_HEIGHT || vinfo.bits_per_pixel != LCD_DEPTH)
63 {
64 panicf("Unexpected framebuffer resolution: %dx%dx%d\n", vinfo.xres,
65 vinfo.yres, vinfo.bits_per_pixel);
66 }
67#endif
68 /* Note: we use a framebuffer size of width*height*bbp. We cannot trust the
69 * values returned by the driver for line_length */
70
71 /* map framebuffer */
72 framebuffer = mmap(0, FRAMEBUFFER_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
73 if((void *)framebuffer == MAP_FAILED)
74 {
75 panicf("Cannot map framebuffer");
76 }
77
78#ifdef HAVE_LCD_ENABLE
79 lcd_set_active(true);
80#endif
81}
82
83#ifdef HAVE_LCD_SHUTDOWN
84void lcd_shutdown(void)
85{
86 munmap(framebuffer, FRAMEBUFFER_SIZE);
87 close(fd);
88}
89#endif
90
91void lcd_enable(bool on)
92{
93 const char * const sysfs_fb_blank = "/sys/class/graphics/fb0/blank";
94
95#ifdef HAVE_LCD_SLEEP
96 if (lcd_active() != on)
97#endif
98 {
99 sysfs_set_int(sysfs_fb_blank, on ? 0 : 1);
100#ifdef HAVE_LCD_ENABLE
101 lcd_set_active(on);
102#endif
103
104 if (on)
105 {
106 send_event(LCD_EVENT_ACTIVATION, NULL);
107 }
108 }
109}
110
111static void redraw(void)
112{
113 ioctl(fd, FBIOPAN_DISPLAY, &vinfo);
114}
115
116extern void lcd_copy_buffer_rect(fb_data *dst, const fb_data *src,
117 int width, int height);
118
119void lcd_update(void)
120{
121#ifdef HAVE_LCD_SLEEP
122 if (lcd_active() != on)
123#endif
124 {
125 /* Copy the Rockbox framebuffer to the second framebuffer */
126 lcd_copy_buffer_rect(LCD_FRAMEBUF_ADDR(0, 0), FBADDR(0,0),
127 LCD_WIDTH*LCD_HEIGHT, 1);
128 redraw();
129 }
130}
131
132void lcd_update_rect(int x, int y, int width, int height)
133{
134#ifdef HAVE_LCD_SLEEP
135 if (lcd_active() != on)
136#endif
137 {
138 fb_data *dst = LCD_FRAMEBUF_ADDR(x, y);
139 fb_data * src = FBADDR(x,y);
140
141 /* Copy part of the Rockbox framebuffer to the second framebuffer */
142 if (width < LCD_WIDTH)
143 {
144 /* Not full width - do line-by-line */
145 lcd_copy_buffer_rect(dst, src, width, height);
146 }
147 else
148 {
149 /* Full width - copy as one line */
150 lcd_copy_buffer_rect(dst, src, LCD_WIDTH*height, 1);
151 }
152 redraw();
153 }
154}