Fix the missing cover-panel reaction with a 9-bit panel path and sign-off probe

Live diagnosis with the flip physically closed showed the wake chain is
intact: bananarchy-coverctl BUTTON/WAKE, the lid gate and sxmo_state.sh set
unlock all reached backend=spidev visible=1 mux=closed, with the daemon
holding /dev/spidev0.1, the gpiochip and its line handles. The outer panel
itself never reacted. Register reads over SPI return zeros (write-only
panels), gpio21 stays static, and a reversible panel-mipi-dbi-spi/spidev
rebind on spi0.0 showed the shared gpio110 D/C path is also unreadable, so
the missing piece is the panel framing: the KaiOS downstream DTS labels
gpio21 TE, not D/C, and Qualcomm MDSS SPI carries D/C as the ninth bit.

bananarchy-cover-idle now defaults to 9-bit MIPI DBI: it releases gpio21,
claims only the reset line, and frames every command and pixel as a
little-endian 9-bit word with D/C in bit 8. spi_word_bits = 8 keeps the old
D/C-GPIO path. A PROBE command walks twelve combinations of word width,
gpio13 mux level, reset/D-C polarity and 25 MHz / 5 MHz clock, re-initialising
the panel and drawing TEST bars; STATUS reports bits= and probe=case N/12.
bananarchy-cover-probe.sh drives all twelve cases with a three-second hold so
the working wiring can be written back to cover-display.conf.

wanted_device() in common.h now also matches KEY_POWER, so the pm8941_pwrkey
device (KEY_POWER only) is no longer invisible to bananarchy-volume-keys and
all three outer buttons can produce a cover wake.

Rebuilt the a1108/dejavu nokia-beatles image and pinned the verified hash
57d140e9cdf05631a6620b639d143350b9984b2170592fb927c93bfb18f67a2b in
check-rebuild.sh. e2fsck -fn passed on both partitions, debugfs confirms
seven updated rootfs files byte-for-byte, and the bootfs sync, boot image
check, artifact sync, host tests and rebuild preflight all pass.

Eyes-on confirmation of which case lights the cover, and the cover backlight
source, are still required; this is an intermediate checkpoint.
This commit is contained in:
Luxferre committed 2026-11-10 20:56:42 +02:00
1 parent 2857ef4374
commit 5f8b7c88ac
15 files changed
+252 -28

No files matched your search

+147 -15
View File
@@ -124,6 +124,10 @@ struct cover_hw {
int reset_assert_level;
int reset_idle_level;
unsigned int speed_hz;
int word_bits;
int panel_lines;
int probe_index;
char probe_desc[96];
int sim;
int spi_enabled;
int fd_spi;
@@ -136,6 +140,30 @@ struct cover_hw {
int initialized;
};
/* Hardware sign-off cases for the external GC9305. The KaiOS downstream DTS
* calls gpio21 "TE", not D/C, and Qualcomm MDSS SPI sends D/C as the ninth
* bit, so both 8-bit (D/C on a GPIO) and 9-bit (D/C in bit 8) are plausible.
* PROBE walks these while drawing TEST bars; the working case is written to
* /etc/bananarchy/cover-display.conf afterwards. */
struct probe_case {
int bits;
int mux;
int reset;
int dc;
unsigned int speed;
};
static const struct probe_case probe_cases[] = {
/* 9-bit first: the downstream DTS labels gpio21 TE and MDSS SPI carries
* D/C in bit 8, so this is the best-supported wiring. */
{9, 1, 0, 0, 25000000}, {9, 1, 1, 0, 25000000},
{9, 0, 0, 0, 25000000}, {9, 0, 1, 0, 25000000},
{9, 1, 0, 0, 5000000}, {9, 0, 1, 0, 5000000},
{8, 1, 0, 0, 25000000}, {8, 1, 1, 0, 25000000},
{8, 1, 0, 1, 25000000}, {8, 1, 1, 1, 25000000},
{8, 0, 0, 0, 25000000}, {8, 1, 0, 0, 5000000},
};
struct glyph {
char ch;
unsigned char col[5];
@@ -530,19 +558,49 @@ static int hw_xfer(struct cover_hw *hw, const unsigned char *tx, size_t len,
static int hw_dc(struct cover_hw *hw, int level)
{
unsigned char values[2];
if(hw->word_bits == 9)
return 1;
values[0] = (unsigned char)level;
values[1] = (unsigned char)hw->reset_idle_level;
return hw_gpio_set(hw, hw->fd_panel, values, 2);
}
static int hw_reset_set(struct cover_hw *hw, int level)
{
unsigned char values[2];
if(hw->panel_lines == 1) {
values[0] = (unsigned char)level;
return hw_gpio_set(hw, hw->fd_panel, values, 1);
}
values[0] = (unsigned char)hw->dc_data_level;
values[1] = (unsigned char)level;
return hw_gpio_set(hw, hw->fd_panel, values, 2);
}
static int hw_command(struct cover_hw *hw, unsigned char cmd,
const unsigned char *params, size_t n)
{
char line[64];
snprintf(line, sizeof(line), "cmd %02x %zu", cmd, n);
snprintf(line, sizeof(line), "cmd %02x %zu bits=%d", cmd, n,
hw->word_bits);
hw_event(hw, line);
if(hw->sim)
return 1;
if(hw->word_bits == 9) {
/* MIPI DBI Type C: D/C is bit 8 of each little-endian 9-bit word. */
unsigned char buf[64];
size_t used = 0;
size_t i;
if((n + 1) * 2 > sizeof(buf))
return 0;
buf[used++] = cmd;
buf[used++] = 0;
for(i = 0; i < n; i++) {
buf[used++] = params[i];
buf[used++] = 1;
}
return hw_xfer(hw, buf, used, 1);
}
if(!hw_dc(hw, hw->dc_command_level))
return 0;
if(!hw_xfer(hw, &cmd, 1, n ? 0 : 1))
@@ -607,7 +665,6 @@ static int hw_activate(struct cover_hw *hw)
unsigned int panel_offsets[2];
unsigned char mux_default[1];
unsigned char panel_default[2];
unsigned char values[2];
int fd;
if(!hw->spi_enabled)
return 0;
@@ -631,11 +688,18 @@ static int hw_activate(struct cover_hw *hw)
hw_gpio_set(hw, hw->fd_mux, mux_value, 1);
}
if(!hw->claimed) {
panel_offsets[0] = hw->dc_gpio;
panel_offsets[1] = hw->reset_gpio;
panel_default[0] = (unsigned char)hw->dc_data_level;
panel_default[1] = (unsigned char)hw->reset_idle_level;
fd = hw_gpio_request(hw, panel_offsets, panel_default, 2);
hw->panel_lines = hw->word_bits == 9 ? 1 : 2;
if(hw->panel_lines == 1) {
panel_offsets[0] = hw->reset_gpio;
panel_default[0] = (unsigned char)hw->reset_idle_level;
} else {
panel_offsets[0] = hw->dc_gpio;
panel_offsets[1] = hw->reset_gpio;
panel_default[0] = (unsigned char)hw->dc_data_level;
panel_default[1] = (unsigned char)hw->reset_idle_level;
}
fd = hw_gpio_request(hw, panel_offsets, panel_default,
(unsigned int)hw->panel_lines);
if(fd < 0)
return 0;
hw->fd_panel = fd;
@@ -648,6 +712,7 @@ static int hw_activate(struct cover_hw *hw)
hw->fd_spi = open(hw->spi_path, O_RDWR | O_CLOEXEC);
if(hw->fd_spi < 0)
return 0;
bits = (unsigned char)hw->word_bits;
if(ioctl(hw->fd_spi, BA_SPI_IOC_WR_MODE, &mode) < 0 ||
ioctl(hw->fd_spi, BA_SPI_IOC_WR_BITS, &bits) < 0 ||
ioctl(hw->fd_spi, BA_SPI_IOC_WR_SPEED, &speed) < 0)
@@ -656,13 +721,10 @@ static int hw_activate(struct cover_hw *hw)
}
if(!hw->initialized) {
/* Reset pulse on the external panel, then replay its firmware stream. */
values[0] = (unsigned char)hw->dc_data_level;
values[1] = (unsigned char)hw->reset_assert_level;
hw_gpio_set(hw, hw->fd_panel, values, 2);
hw_reset_set(hw, hw->reset_assert_level);
if(!hw->sim)
poll(NULL, 0, 20);
values[1] = (unsigned char)hw->reset_idle_level;
hw_gpio_set(hw, hw->fd_panel, values, 2);
hw_reset_set(hw, hw->reset_idle_level);
if(!hw->sim)
poll(NULL, 0, 150);
if(!hw_init_panel(hw))
@@ -683,6 +745,37 @@ static int hw_frame(struct cover_hw *hw, const struct frame *fb, int lit)
hw_event(hw, line);
if(hw->sim)
return 1;
if(hw->word_bits == 9) {
unsigned char start[2];
unsigned char *words;
size_t i;
size_t left;
const unsigned char *p;
start[0] = 0x2c;
start[1] = 0;
if(!hw_xfer(hw, start, 2, 0))
return 0;
words = malloc(size * 2);
if(!words)
return 0;
for(i = 0; i < size; i++) {
words[i * 2] = fb->pixels[i];
words[i * 2 + 1] = 1;
}
p = words;
left = size * 2;
while(left) {
size_t chunk = left > COVER_SPI_CHUNK ? COVER_SPI_CHUNK : left;
if(!hw_xfer(hw, p, chunk, chunk == left)) {
free(words);
return 0;
}
p += chunk;
left -= chunk;
}
free(words);
return 1;
}
if(!hw_dc(hw, hw->dc_command_level))
return 0;
if(!hw_xfer(hw, &cmd, 1, 0))
@@ -904,6 +997,10 @@ static void cover_hw_init(struct cover_hw *hw)
hw->reset_assert_level = 0;
hw->reset_idle_level = 1;
hw->speed_hz = 25000000;
hw->word_bits = 9;
hw->panel_lines = 1;
hw->probe_index = -1;
safe_copy(hw->probe_desc, sizeof(hw->probe_desc), "none");
hw->fd_spi = -1;
hw->fd_chip = -1;
hw->fd_mux = -1;
@@ -1000,6 +1097,10 @@ static void read_config(const char *path, char *socket_path, size_t splen,
v = strtol(value, NULL, 10);
if(v >= 1000000 && v <= 50000000)
hw->speed_hz = (unsigned int)v;
} else if(strcmp(key, "spi_word_bits") == 0) {
v = strtol(value, NULL, 10);
if(v == 8 || v == 9)
hw->word_bits = (int)v;
}
}
fclose(handle);
@@ -1152,10 +1253,39 @@ static void handle_command(char *buffer, struct state *state,
hw->reset_assert_level = config_level(value, hw->reset_assert_level);
else if(strcmp(key, "reset_idle_level") == 0)
hw->reset_idle_level = config_level(value, hw->reset_idle_level);
else
else if(strcmp(key, "spi_word_bits") == 0) {
long bits = strtol(value, NULL, 10);
if(bits == 8 || bits == 9)
hw->word_bits = (int)bits;
else
return;
} else
return;
cover_hw_release(hw);
*redraw = 1;
} else if(strcmp(command, "PROBE") == 0) {
const struct probe_case *p;
hw->probe_index = (hw->probe_index + 1) %
(int)(sizeof(probe_cases) / sizeof(probe_cases[0]));
p = &probe_cases[hw->probe_index];
hw->word_bits = p->bits;
hw->mux_closed_level = p->mux;
hw->mux_open_level = p->mux ? 0 : 1;
hw->reset_assert_level = p->reset;
hw->reset_idle_level = p->reset ? 0 : 1;
hw->dc_command_level = p->dc;
hw->dc_data_level = p->dc ? 0 : 1;
hw->speed_hz = p->speed;
snprintf(hw->probe_desc, sizeof(hw->probe_desc),
"case %d/%d bits=%d mux=%d reset=%d dc=%d speed=%u",
hw->probe_index + 1,
(int)(sizeof(probe_cases) / sizeof(probe_cases[0])),
p->bits, p->mux, p->reset, p->dc, p->speed);
cover_hw_release(hw);
state->test = 2;
state->visible = 1;
state->last_input_ms = now_ms();
*redraw = 1;
} else if(strcmp(command, "TEST") == 0) {
char *mode = strtok_r(NULL, " \t\r\n", &save);
if(mode)
@@ -1195,11 +1325,13 @@ static void reply_for(char *buffer, const struct state *state,
} else if(strcmp(command, "STATUS") == 0) {
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\n",
"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");
hw->mux_claimed ? (hw->claimed ? "closed" : "open") : "free",
hw->word_bits, hw->probe_desc);
} else if(strcmp(command, "LID") == 0) {
snprintf(reply, len, "OK lid=%s\n", state->lid);
} else if(strcmp(command, "TEST") == 0) {
+7 -1
View File
@@ -34,6 +34,9 @@
#define SW_KEYPAD_SLIDE 0x0a
#define KEY_VOLUMEDOWN 114
#define KEY_VOLUMEUP 115
#ifndef KEY_POWER
#define KEY_POWER 116
#endif
#define BA_IOC(dir, type, nr, size) \
(((unsigned int)(dir) << 30) | ((unsigned int)(type) << 8) | \
((unsigned int)(nr) << 0) | ((unsigned int)(size) << 16))
@@ -173,8 +176,11 @@ static BA_UNUSED int wanted_device(int fd, enum watch_filter filter)
return device_has_code(fd, EV_SW, SW_LID) ||
device_has_code(fd, EV_SW, SW_KEYPAD_SLIDE);
}
/* The End/Power key lives on a KEY_POWER-only device (pm8941_pwrkey),
* so it must be watched too or the third outer button is invisible. */
return device_has_code(fd, EV_KEY, KEY_VOLUMEUP) ||
device_has_code(fd, EV_KEY, KEY_VOLUMEDOWN);
device_has_code(fd, EV_KEY, KEY_VOLUMEDOWN) ||
device_has_code(fd, EV_KEY, KEY_POWER);
}
static BA_UNUSED void prune_devices(struct watch_list *list)