Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display configuration: Multiple fixes #217

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions src/display.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ static dcp_dev_t *dcp;
static dcp_iboot_if_t *iboot;
static u64 fb_dva;
static u64 fb_size;
static bool config_done;
static bool display_is_external;

#define abs(x) ((x) >= 0 ? (x) : -(x))
Expand Down Expand Up @@ -233,9 +234,11 @@ int display_parse_mode(const char *config, dcp_timing_mode_t *mode, struct displ

const char *option = config;
while (option && opts) {
if (!strncmp(option + 1, "retina", 6))
if (!strncmp(option, "retina", 6))
opts->retina = true;
option = strchr(option + 1, ',');
option = strchr(option, ',');
if (option)
option += 1;
}

printf("display: want mode: valid=%d %dx%d %d.%02d Hz\n", mode->valid, mode->width,
Expand Down Expand Up @@ -302,6 +305,8 @@ int display_configure(const char *config)
return ret;
}

config_done = true;

// Detect if display is connected
int timing_cnt, color_cnt;
int hpd = 0, retries = 0;
Expand Down Expand Up @@ -430,14 +435,15 @@ int display_configure(const char *config)

printf("display: swapped! (swap_id=%d)\n", ret);

u32 depth = 30 | (opts.retina ? FB_DEPTH_FLAG_RETINA : 0);
if (fb_pa != cur_boot_args.video.base || cur_boot_args.video.stride != stride ||
cur_boot_args.video.width != tbest.width || cur_boot_args.video.height != tbest.height ||
cur_boot_args.video.depth != 30) {
cur_boot_args.video.depth != depth) {
cur_boot_args.video.base = fb_pa;
cur_boot_args.video.stride = stride;
cur_boot_args.video.width = tbest.width;
cur_boot_args.video.height = tbest.height;
cur_boot_args.video.depth = 30 | (opts.retina ? FB_DEPTH_FLAG_RETINA : 0);
cur_boot_args.video.depth = depth;
fb_reinit();
}

Expand All @@ -457,6 +463,17 @@ int display_configure(const char *config)
return 1;
}

void display_finish_config(void)
{
if (!config_done && display_is_external) {
display_configure(NULL);
}

// Kick DCP to sleep, so dodgy monitors which cause reconnect cycles don't cause us to lose the
// framebuffer.
display_shutdown(DCP_SLEEP_IF_EXTERNAL);
}

int display_init(void)
{
int node = adt_path_offset(adt, "/arm-io/disp0");
Expand All @@ -467,22 +484,13 @@ int display_init(void)
}

display_is_external = adt_getprop(adt, node, "external", NULL);
config_done = false;
if (display_is_external)
printf("display: Display is external\n");
else
printf("display: Display is internal\n");

if (cur_boot_args.video.width == 640 && cur_boot_args.video.height == 1136) {
printf("display: Dummy framebuffer found, initializing display\n");
return display_configure(NULL);
} else if (display_is_external) {
printf("display: External display found, reconfiguring\n");
return display_configure(NULL);
} else {
printf("display: Display is already initialized (%ldx%ld)\n", cur_boot_args.video.width,
cur_boot_args.video.height);
return 0;
}
return 0;
}

void display_shutdown(dcp_shutdown_mode mode)
Expand Down
1 change: 1 addition & 0 deletions src/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ typedef enum _dcp_shutdown_mode {
int display_init(void);
int display_start_dcp(void);
int display_configure(const char *config);
void display_finish_config(void);
void display_shutdown(dcp_shutdown_mode mode);

#endif
6 changes: 2 additions & 4 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,11 @@ void run_actions(void)

if (payload_run() == 0) {
printf("Valid payload found\n");
display_finish_config();
return;
}

display_finish_config();
fb_set_active(true);

printf("No valid payload found\n");
Expand Down Expand Up @@ -138,9 +140,6 @@ void m1n1_main(void)

#ifdef USE_FB
display_init();
// Kick DCP to sleep, so dodgy monitors which cause reconnect cycles don't cause us to lose the
// framebuffer.
display_shutdown(DCP_SLEEP_IF_EXTERNAL);
fb_init(false);
fb_display_logo();
#ifdef FB_SILENT_MODE
Expand All @@ -167,7 +166,6 @@ void m1n1_main(void)
nvme_shutdown();
exception_shutdown();
usb_iodev_shutdown();
display_shutdown(DCP_SLEEP_IF_EXTERNAL);
#ifdef USE_FB
fb_shutdown(next_stage.restore_logo);
#endif
Expand Down