Drive the 2720 Flip cover panel through the kernel panel driver
Autonomous testing (clean reboot, kernel SPI statistics, kHz GPIO sweeps, CS0/CS1 register reads, battery/ALS/hwmon checks, host webcam differential imaging) showed all twelve userspace PROBE cases delivered complete, error-free SPI traffic while the cover stayed dark. The QUP5 pinctrl group has one CS line and gpio110 (the kernel panel-mipi-dbi-spi driver's D/C) is shared behind the gpio13 bus switch, so no userspace D/C framing can work. backend = kernel is now the default. While the flip is closed the compiled cover daemon claims only gpio13 (mux) and gpio23 (cover reset), switches the bus to the cover and forces a DPMS off/on cycle through bananarchy-cover-dpms.sh reinit; mipi_dbi_enable() then replays the kernel's firmware init sequence onto the external panel with CS0 and gpio110 D/C. The cover UI is rendered as a 240x240 XR24 damage rect at the top of /dev/fb0 using the fbdev stride, which makes mipi_dbi set a 240x240 address window. The main backlight and keypad stay at 0, so only the outer panel can light. On open the mux returns to the internal panel and the lid daemon requests a reinit after an 80 ms settle. Live verification: closed -> backend=kernel-dark (DPMS off); BUTTON -> backend=kernel, dpms=On, gpio13 high, 172800 non-zero bytes of cover UI in /dev/fb0, kernel spi0.0 +460899 bytes and userspace spi0.1 +0, zero SPI errors; BLANK -> kernel-dark/DPMS off; LID OPEN -> mux=free, gpio13 low. Main backlight and keypad stayed at 0 throughout. All spidev/8-bit/9-bit paths, PROBE, bananarchy-cover-probe.sh and backend = fb|spidev|none remain as runtime rollback paths. New host test scripts/test-cover-kernel.py plus check-rebuild.sh guards. Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash ce0542321990a8cff8ab122c0a47c0684fcc7e3d5f6fc97e74b3b0ea4c4826b5 in check-rebuild.sh. e2fsck -fn passed on both partitions, debugfs confirms the rebuilt daemons, helper and config byte-for-byte, and the bootfs sync, boot image check, artifact sync, host tests and rebuild preflight all pass. Limitation: Xorg shares /dev/fb0, so its repaints can still overwrite part of the cover UI; a dedicated override-redirect cover compositor is next. Physical illumination is still unverified from the host.
This commit is contained in:
1 parent
5f8b7c88ac
commit
c939687138
15 files changed
+468
-21
No files matched your search
@@ -108,6 +108,16 @@ _Static_assert(sizeof(struct ba_gpiohandle_request) == 364,
|
||||
_Static_assert(sizeof(struct ba_spi_ioc_transfer) == 32,
|
||||
"spidev transfer ABI size");
|
||||
|
||||
static char *const session_env[] = {
|
||||
(char *)"PATH=/home/user/.local/bin:/home/user/.config/sxmo/hooks:/usr/share/sxmo/default_hooks:/usr/local/bin:/usr/bin:/bin:/sbin:/usr/sbin",
|
||||
(char *)"HOME=/home/user",
|
||||
(char *)"USER=user",
|
||||
(char *)"DISPLAY=:0",
|
||||
(char *)"XDG_RUNTIME_DIR=/run/user/10000",
|
||||
(char *)"SHELL=/bin/sh",
|
||||
NULL
|
||||
};
|
||||
|
||||
struct cover_hw {
|
||||
char backend[16];
|
||||
char spi_path[128];
|
||||
@@ -128,6 +138,9 @@ struct cover_hw {
|
||||
int panel_lines;
|
||||
int probe_index;
|
||||
char probe_desc[96];
|
||||
char kernel_fb[128];
|
||||
char kernel_dpms[128];
|
||||
int kernel_lit;
|
||||
int sim;
|
||||
int spi_enabled;
|
||||
int fd_spi;
|
||||
@@ -885,6 +898,164 @@ static int cover_main_panel_is_off(void)
|
||||
return strncmp(buf, "Off", 3) == 0;
|
||||
}
|
||||
|
||||
/* --- Kernel-owned cover path ----------------------------------------------
|
||||
* The external panel sits behind the gpio13 bus switch on the same QUP5 bus
|
||||
* as the internal panel. The kernel panel-mipi-dbi-spi driver owns CS0, the
|
||||
* shared gpio110 D/C line and the firmware init stream, so userspace cannot
|
||||
* drive the cover with its own D/C framing. Instead, while the flip is closed
|
||||
* we switch the mux to the cover, release its reset, force a DRM DPMS off/on
|
||||
* cycle (which makes the kernel driver replay its init sequence onto the panel
|
||||
* now on the bus) and render the cover UI into the main framebuffer. The main
|
||||
* backlight and keypad stay at 0, so only the outer panel can light up.
|
||||
*/
|
||||
static void hw_dpms(struct cover_hw *hw, const char *mode)
|
||||
{
|
||||
char line[64];
|
||||
if(hw->sim) {
|
||||
snprintf(line, sizeof(line), "dpms %s", mode);
|
||||
hw_event(hw, line);
|
||||
return;
|
||||
}
|
||||
if(!hw->kernel_dpms[0])
|
||||
return;
|
||||
{
|
||||
char *const argv[] = { hw->kernel_dpms, (char *)mode, NULL };
|
||||
daemon_spawn_env(argv, (char *const *)session_env);
|
||||
}
|
||||
}
|
||||
|
||||
static int cover_kernel_claim(struct cover_hw *hw)
|
||||
{
|
||||
unsigned int offsets[2];
|
||||
unsigned char defaults[2];
|
||||
unsigned char values[2];
|
||||
int fd;
|
||||
if(hw->fd_mux >= 0 || hw->mux_claimed)
|
||||
return 1;
|
||||
offsets[0] = hw->mux_gpio;
|
||||
offsets[1] = hw->reset_gpio;
|
||||
defaults[0] = (unsigned char)hw->mux_open_level;
|
||||
defaults[1] = (unsigned char)hw->reset_idle_level;
|
||||
fd = hw_gpio_request(hw, offsets, defaults, 2);
|
||||
if(fd < 0)
|
||||
return 0;
|
||||
hw->fd_mux = fd;
|
||||
hw->mux_claimed = 1;
|
||||
values[0] = (unsigned char)hw->mux_closed_level;
|
||||
values[1] = (unsigned char)hw->reset_idle_level;
|
||||
return hw_gpio_set(hw, hw->fd_mux, values, 2);
|
||||
}
|
||||
|
||||
static void cover_kernel_release(struct cover_hw *hw)
|
||||
{
|
||||
unsigned char values[2];
|
||||
/* The spidev backend owns fd_mux too; only the kernel backend may release
|
||||
* it here, or its STATUS would lose the restored mux state. */
|
||||
if(strcmp(hw->backend, "kernel") != 0)
|
||||
return;
|
||||
if(!hw->mux_claimed)
|
||||
return;
|
||||
values[0] = (unsigned char)hw->mux_open_level;
|
||||
values[1] = (unsigned char)hw->reset_idle_level;
|
||||
hw_gpio_set(hw, hw->fd_mux, values, 2);
|
||||
hw_event(hw, "release");
|
||||
if(!hw->sim && hw->fd_mux >= 0)
|
||||
close(hw->fd_mux);
|
||||
hw->fd_mux = -1;
|
||||
hw->mux_claimed = 0;
|
||||
hw->kernel_lit = -1;
|
||||
}
|
||||
|
||||
static int cover_kernel_frame(struct cover_hw *hw, const struct state *state)
|
||||
{
|
||||
unsigned int width = COVER_SPI_WIDTH;
|
||||
unsigned int height = COVER_SPI_HEIGHT;
|
||||
unsigned int stride = width * 4;
|
||||
char sysfs[128];
|
||||
unsigned int parsed = 0;
|
||||
size_t size;
|
||||
unsigned char *mem;
|
||||
struct frame fb;
|
||||
int fd;
|
||||
char line[96];
|
||||
/* Match the DRM fbdev stride: 240x320 XR24 is padded to 1024 bytes/row.
|
||||
* Writing a 240x240 damage rect makes mipi_dbi set a 240x240 address
|
||||
* window, which is exactly the cover panel's native geometry. */
|
||||
snprintf(sysfs, sizeof(sysfs), "/sys/class/graphics/fb0/stride");
|
||||
if(read_uint_file(sysfs, &parsed) && parsed >= width * 4)
|
||||
stride = parsed;
|
||||
size = (size_t)stride * height;
|
||||
mem = calloc(1, size);
|
||||
if(!mem)
|
||||
return 0;
|
||||
fb.pixels = mem;
|
||||
fb.width = width;
|
||||
fb.height = height;
|
||||
fb.stride = stride;
|
||||
fb.bpp = 32;
|
||||
render_frame(&fb, state);
|
||||
snprintf(line, sizeof(line), "kernel frame lit=%d size=%zu",
|
||||
cover_is_lit(state), size);
|
||||
hw_event(hw, line);
|
||||
fd = open(hw->kernel_fb, O_RDWR | O_CLOEXEC);
|
||||
if(fd < 0) {
|
||||
free(mem);
|
||||
return hw->sim;
|
||||
}
|
||||
if(lseek(fd, 0, SEEK_SET) < 0 || !write_all(fd, mem, size)) {
|
||||
free(mem);
|
||||
close(fd);
|
||||
return 0;
|
||||
}
|
||||
fsync(fd);
|
||||
close(fd);
|
||||
free(mem);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const char *cover_kernel_draw(struct cover_hw *hw,
|
||||
const struct state *state)
|
||||
{
|
||||
int lit = cover_is_lit(state);
|
||||
if(!cover_kernel_claim(hw))
|
||||
return "none";
|
||||
if(lit != hw->kernel_lit) {
|
||||
if(lit) {
|
||||
hw_dpms(hw, "reinit");
|
||||
if(!hw->sim)
|
||||
poll(NULL, 0, 180);
|
||||
} else {
|
||||
hw_dpms(hw, "off");
|
||||
}
|
||||
hw->kernel_lit = lit;
|
||||
}
|
||||
if(lit && !cover_kernel_frame(hw, state))
|
||||
return "none";
|
||||
return lit ? "kernel" : "kernel-dark";
|
||||
}
|
||||
|
||||
/* The kernel backend keeps DPMS ON while the cover is lit (that is how the
|
||||
* DRM driver flushes to it), so its safety condition is the main backlight
|
||||
* being dark, not DPMS. */
|
||||
static int cover_main_backlight_is_off(void)
|
||||
{
|
||||
const char *path = getenv("BANANARCHY_COVER_BL_PATH");
|
||||
char buf[32];
|
||||
ssize_t got;
|
||||
int fd;
|
||||
if(!path || !*path)
|
||||
path = "/sys/class/backlight/backlight/brightness";
|
||||
fd = open(path, O_RDONLY | O_CLOEXEC);
|
||||
if(fd < 0)
|
||||
return 1;
|
||||
got = read(fd, buf, sizeof(buf) - 1);
|
||||
close(fd);
|
||||
if(got <= 0)
|
||||
return 1;
|
||||
buf[got] = '\0';
|
||||
return atoi(buf) == 0;
|
||||
}
|
||||
|
||||
static const char *cover_draw(struct cover_hw *hw, const char *fb_path,
|
||||
const struct state *state)
|
||||
{
|
||||
@@ -894,14 +1065,23 @@ static const char *cover_draw(struct cover_hw *hw, const char *fb_path,
|
||||
strcmp(hw->backend, "none") != 0 && fb_present;
|
||||
if(flip_open) {
|
||||
cover_hw_release(hw);
|
||||
cover_kernel_release(hw);
|
||||
if(prefer_fb)
|
||||
return draw_frame(fb_path, state) ? "fb" : "none";
|
||||
return "idle";
|
||||
}
|
||||
if(strcmp(hw->backend, "none") == 0) {
|
||||
cover_hw_release(hw);
|
||||
cover_kernel_release(hw);
|
||||
return "none";
|
||||
}
|
||||
if(strcmp(hw->backend, "kernel") == 0) {
|
||||
if(!cover_main_backlight_is_off()) {
|
||||
cover_kernel_release(hw);
|
||||
return "pending";
|
||||
}
|
||||
return cover_kernel_draw(hw, state);
|
||||
}
|
||||
if(prefer_fb) {
|
||||
cover_hw_release(hw);
|
||||
return draw_frame(fb_path, state) ? "fb" : "none";
|
||||
@@ -1000,12 +1180,24 @@ static void cover_hw_init(struct cover_hw *hw)
|
||||
hw->word_bits = 9;
|
||||
hw->panel_lines = 1;
|
||||
hw->probe_index = -1;
|
||||
hw->kernel_lit = -1;
|
||||
safe_copy(hw->kernel_fb, sizeof(hw->kernel_fb), "/dev/fb0");
|
||||
safe_copy(hw->kernel_dpms, sizeof(hw->kernel_dpms),
|
||||
"/usr/bin/bananarchy-cover-dpms.sh");
|
||||
safe_copy(hw->probe_desc, sizeof(hw->probe_desc), "none");
|
||||
hw->fd_spi = -1;
|
||||
hw->fd_chip = -1;
|
||||
hw->fd_mux = -1;
|
||||
hw->fd_panel = -1;
|
||||
hw->fd_sim = -1;
|
||||
{
|
||||
const char *fb = getenv("BANANARCHY_COVER_MAIN_FB");
|
||||
const char *dp = getenv("BANANARCHY_COVER_DPMS_HELPER");
|
||||
if(fb && *fb)
|
||||
safe_copy(hw->kernel_fb, sizeof(hw->kernel_fb), fb);
|
||||
if(dp && *dp)
|
||||
safe_copy(hw->kernel_dpms, sizeof(hw->kernel_dpms), dp);
|
||||
}
|
||||
sim = getenv("BANANARCHY_COVER_SPI_SIM");
|
||||
if(sim && *sim) {
|
||||
safe_copy(hw->sim_path, sizeof(hw->sim_path), sim);
|
||||
@@ -1065,6 +1257,10 @@ static void read_config(const char *path, char *socket_path, size_t splen,
|
||||
safe_copy(hw->backend, sizeof(hw->backend), value);
|
||||
else if(strcmp(key, "spi_device") == 0)
|
||||
safe_copy(hw->spi_path, sizeof(hw->spi_path), value);
|
||||
else if(strcmp(key, "main_fb_device") == 0)
|
||||
safe_copy(hw->kernel_fb, sizeof(hw->kernel_fb), value);
|
||||
else if(strcmp(key, "kernel_dpms_helper") == 0)
|
||||
safe_copy(hw->kernel_dpms, sizeof(hw->kernel_dpms), value);
|
||||
else if(strcmp(key, "gpiochip_device") == 0)
|
||||
safe_copy(hw->gpio_path, sizeof(hw->gpio_path), value);
|
||||
else if(strcmp(key, "panel_firmware") == 0)
|
||||
@@ -1323,14 +1519,17 @@ static void reply_for(char *buffer, const struct state *state,
|
||||
if(strcmp(command, "PING") == 0) {
|
||||
snprintf(reply, len, "OK pong\n");
|
||||
} else if(strcmp(command, "STATUS") == 0) {
|
||||
const char *mux = "free";
|
||||
if(hw->mux_claimed)
|
||||
mux = strcmp(hw->backend, "kernel") == 0 ? "cover" :
|
||||
(hw->claimed ? "closed" : "open");
|
||||
snprintf(reply, len,
|
||||
"OK lid=%s backend=%s enabled=%d visible=%d blank_ms=%lld "
|
||||
"battery=%d call=%s sms=%d network=%s spi=%d mux=%s "
|
||||
"bits=%d probe=%s\n",
|
||||
state->lid, state->backend, state->enabled, state->visible,
|
||||
state->blank_ms, state->battery, state->call, state->sms,
|
||||
state->network, hw->spi_enabled,
|
||||
hw->mux_claimed ? (hw->claimed ? "closed" : "open") : "free",
|
||||
state->network, hw->spi_enabled, mux,
|
||||
hw->word_bits, hw->probe_desc);
|
||||
} else if(strcmp(command, "LID") == 0) {
|
||||
snprintf(reply, len, "OK lid=%s\n", state->lid);
|
||||
|
||||
@@ -75,8 +75,7 @@ static void run_sxmo_state(const char *action, const char *expected_lid)
|
||||
static void run_dpms(const char *mode)
|
||||
{
|
||||
char *const argv[] = {
|
||||
(char *)"/usr/bin/xset", (char *)"dpms", (char *)"force",
|
||||
(char *)mode, NULL
|
||||
(char *)"/usr/bin/bananarchy-cover-dpms.sh", (char *)mode, NULL
|
||||
};
|
||||
daemon_spawn_env(argv, (char *const *)session_env);
|
||||
}
|
||||
@@ -210,14 +209,17 @@ static void on_transition(int closed)
|
||||
} else {
|
||||
int bl = read_int_file(BRIGHTNESS_SAVE, 10);
|
||||
int kbd = read_int_file(KBD_SAVE, 1);
|
||||
/* Release the cover's shared SPI bus before relighting the main panel. */
|
||||
/* Release the cover's shared SPI bus before relighting the main panel.
|
||||
* The cover daemon restores the mux on this datagram; give it a moment so
|
||||
* the DPMS re-init below hits the internal panel, not the cover. */
|
||||
cover_send("OPEN");
|
||||
poll(NULL, 0, 80);
|
||||
unlink(LOCK_FLAG);
|
||||
write_session_file(state, "unlock");
|
||||
write_text_file(BL_POWER, "0");
|
||||
write_sysfs_int(BRIGHTNESS, bl);
|
||||
write_sysfs_int(KBD_BACKLIGHT, kbd);
|
||||
run_dpms("on");
|
||||
run_dpms("reinit");
|
||||
locker_send("CLOSE\n");
|
||||
run_sxmo_state("unlock", "open");
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user