Skip to content

Commit

Permalink
kboot: Hide the notch
Browse files Browse the repository at this point in the history
Signed-off-by: Hector Martin <[email protected]>
  • Loading branch information
marcan committed Feb 21, 2022
1 parent 5531b9a commit 287a963
Showing 1 changed file with 40 additions and 3 deletions.
43 changes: 40 additions & 3 deletions src/kboot.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,42 @@ static size_t initrd_size = 0;
goto err; \
} while (0)

void get_notchless_fb(u64 *fb_base, u64 *fb_height)
{
*fb_base = cur_boot_args.video.base;
*fb_height = cur_boot_args.video.height;

int node = adt_path_offset(adt, "/product");

if (node < 0) {
printf("FDT: /product node not found\n");
return;
}

u32 val;

if (ADT_GETPROP(adt, node, "partially-occluded-display", &val) < 0 || !val) {
printf("FDT: No notch detected\n");
return;
}

u64 hfrac = cur_boot_args.video.height * 16 / cur_boot_args.video.width;
u64 new_height = cur_boot_args.video.width * hfrac / 16;

if (new_height == cur_boot_args.video.height) {
printf("FDT: Notch detected, but display aspect is already 16:%lu?\n", hfrac);
return;
}

u64 offset = cur_boot_args.video.height - new_height;

printf("display: Hiding notch, %lux%lu -> %lux%lu (+%lu, 16:%lu)\n", cur_boot_args.video.width,
cur_boot_args.video.height, cur_boot_args.video.width, new_height, offset, hfrac);

*fb_base += cur_boot_args.video.stride * offset;
*fb_height = new_height;
}

static int dt_set_chosen(void)
{

Expand Down Expand Up @@ -69,8 +105,9 @@ static int dt_set_chosen(void)
if (fb < 0)
bail("FDT: /chosen node not found in devtree\n");

u64 fb_base = cur_boot_args.video.base;
u64 fb_size = cur_boot_args.video.stride * cur_boot_args.video.height;
u64 fb_base, fb_height;
get_notchless_fb(&fb_base, &fb_height);
u64 fb_size = cur_boot_args.video.stride * fb_height;
u64 fbreg[2] = {cpu_to_fdt64(fb_base), cpu_to_fdt64(fb_size)};
char fbname[32];

Expand All @@ -85,7 +122,7 @@ static int dt_set_chosen(void)
if (fdt_setprop_u32(dt, fb, "width", cur_boot_args.video.width))
bail("FDT: couldn't set framebuffer width\n");

if (fdt_setprop_u32(dt, fb, "height", cur_boot_args.video.height))
if (fdt_setprop_u32(dt, fb, "height", fb_height))
bail("FDT: couldn't set framebuffer height\n");

if (fdt_setprop_u32(dt, fb, "stride", cur_boot_args.video.stride))
Expand Down

0 comments on commit 287a963

Please sign in to comment.