Blank the cover fbdev when off and add panel diagnostics

This commit is contained in:
Luxferre committed 2026-11-10 14:11:00 +02:00
1 parent 7c52d616e7
commit 90e6771700
11 files changed
+121 -11

No files matched your search

+41 -7
View File
@@ -18,6 +18,24 @@
#include <sys/socket.h>
#include <sys/un.h>
/* The armv7 cross sysroot does not always ship linux/fb.h. These UAPI
* values are stable; use the header when it exists, otherwise the numeric
* definitions from linux/fb.h (FBIOBLANK = _IO('F', 0x11) = 0x4611). */
#if defined(__has_include)
#if __has_include(<linux/fb.h>)
#include <linux/fb.h>
#endif
#endif
#ifndef FBIOBLANK
#define FBIOBLANK 0x4611
#endif
#ifndef FB_BLANK_UNBLANK
#define FB_BLANK_UNBLANK 0
#endif
#ifndef FB_BLANK_POWERDOWN
#define FB_BLANK_POWERDOWN 4
#endif
#include "common.h"
#define COVER_LOCK "/run/bananarchy-cover-idle.lock"
@@ -222,9 +240,21 @@ struct state {
int backlight_level;
};
/* Fully off means both a black framebuffer and a zeroed backlight. A missing
* backlight node is normal while the cover panel DT overlay is hardware-gated;
* the black frame still leaves nothing visible on the panel. */
/* A lit cover needs a lit framebuffer, a lit backlight and an unblanked fbdev;
* everything else is "fully off". TEST modes are diagnostic overrides. */
static int cover_is_lit(const struct state *state)
{
if(state->test == 4)
return 0;
if(state->test == 1 || state->test == 2 || state->test == 3)
return 1;
return state->enabled && state->visible &&
strcmp(state->lid, "closed") == 0;
}
/* Fully off means a black framebuffer, a zeroed backlight and an fbdev
* FB_BLANK_POWERDOWN. An empty backlight_path is normal on hardware without
* a separate cover backlight sysfs node; fbdev blanking still powers it down. */
static void set_backlight(const struct state *state, int on)
{
char value[32];
@@ -289,8 +319,7 @@ static int draw_frame(const char *fb_path, const struct state *state)
} else if(state->test == 3) {
frame_rect(&fb, 0, 0, (int)width, (int)height,
rgb888(245, 245, 245));
} else if(state->test == 4 ||
strcmp(state->lid, "open") == 0 || !state->visible) {
} else if(!cover_is_lit(state)) {
frame_rect(&fb, 0, 0, (int)width, (int)height, rgb888(0, 0, 0));
} else {
frame_rect(&fb, 0, 0, (int)width, (int)height, rgb888(8, 12, 26));
@@ -319,6 +348,12 @@ static int draw_frame(const char *fb_path, const struct state *state)
return 0;
}
fsync(fd);
/* DRM fbdev emulation turns FB_BLANK_POWERDOWN into a DPMS-off on the
* external connector, so the cover is electrically dark as well as black.
* Unblank before drawing a lit frame; blank after writing the black one.
* Regular files (host tests / sim backends) simply ignore the ioctl. */
(void)ioctl(fd, FBIOBLANK,
cover_is_lit(state) ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN);
free(mem);
close(fd);
return 1;
@@ -639,8 +674,7 @@ int main(int argc, char **argv)
redraw = 1;
}
if(redraw) {
set_backlight(&state, state.visible || state.test == 2 ||
state.test == 3 || state.test == 1);
set_backlight(&state, cover_is_lit(&state));
snprintf(state.backend, sizeof(state.backend), "%s",
draw_frame(fb_path, &state) ? "fb" : "none");
last_draw = now;