Module Name: src Committed By: jmcneill Date: Sat Mar 17 13:14:27 UTC 2018
Modified Files: src/sys/arch/sgimips/dev: crmfb.c Log Message: Add support for overriding the video mode by setting an ARCS environment variable. If the "crmfb_mode" environment variable is set, treat it as a mode string in the form WIDTHxHEIGHT[@REFRESH] and generate monitor timings using the VESA GTF formula. If set, this overrides the EDID preferred mode. To generate a diff of this commit: cvs rdiff -u -r1.44 -r1.45 src/sys/arch/sgimips/dev/crmfb.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/arch/sgimips/dev/crmfb.c diff -u src/sys/arch/sgimips/dev/crmfb.c:1.44 src/sys/arch/sgimips/dev/crmfb.c:1.45 --- src/sys/arch/sgimips/dev/crmfb.c:1.44 Fri May 19 19:25:53 2017 +++ src/sys/arch/sgimips/dev/crmfb.c Sat Mar 17 13:14:27 2018 @@ -1,4 +1,4 @@ -/* $NetBSD: crmfb.c,v 1.44 2017/05/19 19:25:53 macallan Exp $ */ +/* $NetBSD: crmfb.c,v 1.45 2018/03/17 13:14:27 jmcneill Exp $ */ /*- * Copyright (c) 2007 Jared D. McNeill <jmcne...@invisible.ca> @@ -32,7 +32,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1.44 2017/05/19 19:25:53 macallan Exp $"); +__KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1.45 2018/03/17 13:14:27 jmcneill Exp $"); #include <sys/param.h> #include <sys/systm.h> @@ -57,6 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: crmfb.c,v 1. #include <dev/i2c/i2c_bitbang.h> #include <dev/i2c/ddcvar.h> #include <dev/videomode/videomode.h> +#include <dev/videomode/vesagtf.h> #include <dev/videomode/edidvar.h> #include <arch/sgimips/dev/crmfbreg.h> @@ -232,6 +233,7 @@ static void crmfb_setup_ddc(struct crmfb /* mode setting stuff */ static uint32_t calc_pll(int); /* frequency in kHz */ static int crmfb_set_mode(struct crmfb_softc *, const struct videomode *); +static int crmfb_parse_mode(const char *, struct videomode *); CFATTACH_DECL_NEW(crmfb, sizeof(struct crmfb_softc), crmfb_match, crmfb_attach, NULL, NULL); @@ -254,6 +256,8 @@ crmfb_attach(device_t parent, device_t s unsigned long v; long defattr; const char *consdev; + const char *modestr; + struct videomode mode, *pmode; int rv, i; sc = device_private(self); @@ -305,11 +309,16 @@ crmfb_attach(device_t parent, device_t s sc->sc_console_depth = 8; crmfb_setup_ddc(sc); - if ((sc->sc_edid_info.edid_preferred_mode != NULL)) { - if (crmfb_set_mode(sc, sc->sc_edid_info.edid_preferred_mode)) - aprint_normal_dev(sc->sc_dev, "using %dx%d\n", - sc->sc_width, sc->sc_height); - } + pmode = sc->sc_edid_info.edid_preferred_mode; + + modestr = arcbios_GetEnvironmentVariable("crmfb_mode"); + if (crmfb_parse_mode(modestr, &mode) == 0) + pmode = &mode; + + if (pmode != NULL && crmfb_set_mode(sc, pmode)) + aprint_normal_dev(sc->sc_dev, "using %dx%d\n", + sc->sc_width, sc->sc_height); + /* * first determine how many tiles we need * in 32bit each tile is 128x128 pixels @@ -1859,3 +1868,34 @@ crmfb_set_mode(struct crmfb_softc *sc, c return TRUE; } + +/* + * Parse a mode string in the form WIDTHxHEIGHT[@REFRESH] and return + * monitor timings generated using the VESA GTF formula. + */ +static int +crmfb_parse_mode(const char *modestr, struct videomode *mode) +{ + char *x, *at; + int width, height, refresh; + + if (modestr == NULL) + return EINVAL; + + x = strchr(modestr, 'x'); + at = strchr(modestr, '@'); + + if (x == NULL || (at != NULL && at < x)) + return EINVAL; + + width = strtoul(modestr, NULL, 10); + height = strtoul(x + 1, NULL, 10); + refresh = at ? strtoul(at + 1, NULL, 10) : 60; + + if (width == 0 || height == 0 || refresh == 0) + return EINVAL; + + vesagtf_mode(width, height, refresh, mode); + + return 0; +}