Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci g/c some unused / #if 0-ed goop, support firmwar...
details: https://anonhg.NetBSD.org/src/rev/09d862b082ea
branches: trunk
changeset: 353913:09d862b082ea
user: macallan <macallan%NetBSD.org@localhost>
date: Sun May 28 05:27:13 2017 +0000
description:
g/c some unused / #if 0-ed goop, support firmware-provided EDID, get rid of
private list of video modes
tested on macppc, should Just Work(tm) on sparc64
diffstat:
sys/dev/pci/machfb.c | 260 +++++++++++++++++++++-----------------------------
1 files changed, 112 insertions(+), 148 deletions(-)
diffs (truncated from 539 to 300 lines):
diff -r f0d6dbfba0ff -r 09d862b082ea sys/dev/pci/machfb.c
--- a/sys/dev/pci/machfb.c Sun May 28 04:12:13 2017 +0000
+++ b/sys/dev/pci/machfb.c Sun May 28 05:27:13 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: machfb.c,v 1.92 2016/07/11 11:31:51 msaitoh Exp $ */
+/* $NetBSD: machfb.c,v 1.93 2017/05/28 05:27:13 macallan Exp $ */
/*
* Copyright (c) 2002 Bang Jun-Young
@@ -34,7 +34,7 @@
#include <sys/cdefs.h>
__KERNEL_RCSID(0,
- "$NetBSD: machfb.c,v 1.92 2016/07/11 11:31:51 msaitoh Exp $");
+ "$NetBSD: machfb.c,v 1.93 2017/05/28 05:27:13 macallan Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -124,6 +124,7 @@
int mem_freq;
int ramdac_freq;
int ref_freq;
+ int vclk_freq;
int ref_div;
int log2_vclk_post_div;
@@ -132,10 +133,12 @@
int mclk_post_div;
int mclk_fb_div;
int sc_clock; /* which clock to use */
+ int minref, m;
struct videomode *sc_my_mode;
int sc_edid_size;
uint8_t sc_edid_data[1024];
+ struct edid_info sc_ei;
u_char sc_cmap_red[256];
u_char sc_cmap_green[256];
@@ -205,24 +208,6 @@
"(unknown type)"
};
-static struct videomode mach64_modes[] = {
- /* 640x400 @ 70 Hz, 31.5 kHz */
- { 25175, 640, 664, 760, 800, 400, 409, 411, 450, 0, NULL, },
- /* 640x480 @ 72 Hz, 36.5 kHz */
- { 25175, 640, 664, 760, 800, 480, 491, 493, 525, 0, NULL, },
- /* 800x600 @ 72 Hz, 48.0 kHz */
- { 50000, 800, 856, 976, 1040, 600, 637, 643, 666,
- VID_PHSYNC | VID_PVSYNC, NULL, },
- /* 1024x768 @ 70 Hz, 56.5 kHz */
- { 75000, 1024, 1048, 1184, 1328, 768, 771, 777, 806,
- VID_NHSYNC | VID_NVSYNC, NULL, },
- /* 1152x864 @ 70 Hz, 62.4 kHz */
- { 92000, 1152, 1208, 1368, 1474, 864, 865, 875, 895, 0, NULL, },
- /* 1280x1024 @ 70 Hz, 74.59 kHz */
- { 126500, 1280, 1312, 1472, 1696, 1024, 1032, 1040, 1068,
- VID_NHSYNC | VID_NVSYNC, NULL, }
-};
-
extern const u_char rasops_cmap[768];
static int mach64_match(device_t, cfdata_t, void *);
@@ -235,9 +220,7 @@
static int mach64_get_memsize(struct mach64_softc *);
static int mach64_get_max_ramdac(struct mach64_softc *);
-#if defined(__sparc__) || defined(__powerpc__)
static void mach64_get_mode(struct mach64_softc *, struct videomode *);
-#endif
static int mach64_calc_crtcregs(struct mach64_softc *,
struct mach64_crtcregs *,
@@ -256,8 +239,6 @@
static void mach64_init_lut(struct mach64_softc *);
static void mach64_init_screen(void *, struct vcons_screen *, int, long *);
-static int mach64_set_screentype(struct mach64_softc *,
- const struct wsscreen_descr *);
static int mach64_is_console(struct mach64_softc *);
static void mach64_cursor(void *, int, int, int);
@@ -293,68 +274,13 @@
80, 30,
NULL,
8, 16,
- WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
- &default_mode
-}, mach64_80x25_screen = {
- "80x25", 80, 25,
- NULL,
- 8, 16,
- WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
- &mach64_modes[0]
-}, mach64_80x30_screen = {
- "80x30", 80, 30,
- NULL,
- 8, 16,
- WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
- &mach64_modes[1]
-}, mach64_80x40_screen = {
- "80x40", 80, 40,
- NULL,
- 8, 10,
- WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
- &mach64_modes[0]
-}, mach64_80x50_screen = {
- "80x50", 80, 50,
- NULL,
- 8, 8,
- WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
- &mach64_modes[0]
-}, mach64_100x37_screen = {
- "100x37", 100, 37,
- NULL,
- 8, 16,
- WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
- &mach64_modes[2]
-}, mach64_128x48_screen = {
- "128x48", 128, 48,
- NULL,
- 8, 16,
- WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
- &mach64_modes[3]
-}, mach64_144x54_screen = {
- "144x54", 144, 54,
- NULL,
- 8, 16,
- WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
- &mach64_modes[4]
-}, mach64_160x64_screen = {
- "160x54", 160, 64,
- NULL,
- 8, 16,
- WSSCREEN_WSCOLORS | WSSCREEN_HILIT,
- &mach64_modes[5]
+ WSSCREEN_WSCOLORS | WSSCREEN_HILIT | WSSCREEN_UNDERLINE
+ /* | WSSCREEN_RESIZE */,
+ NULL
};
static const struct wsscreen_descr *_mach64_scrlist[] = {
&mach64_defaultscreen,
- &mach64_80x25_screen,
- &mach64_80x30_screen,
- &mach64_80x40_screen,
- &mach64_80x50_screen,
- &mach64_100x37_screen,
- &mach64_128x48_screen,
- &mach64_144x54_screen,
- &mach64_160x64_screen
};
static struct wsscreen_list mach64_screenlist = {
@@ -366,11 +292,6 @@
struct lwp *);
static paddr_t mach64_mmap(void *, void *, off_t, int);
-#if 0
-static int mach64_load_font(void *, void *, struct wsdisplay_font *);
-#endif
-
-
static struct vcons_screen mach64_console_screen;
/*
@@ -480,15 +401,13 @@
struct pci_attach_args *pa = aux;
struct rasops_info *ri;
prop_data_t edid_data;
-#if defined(__sparc__) || defined(__powerpc__)
const struct videomode *mode = NULL;
-#endif
int bar, id, expected_id;
int is_gx;
const char **memtype_names;
struct wsemuldisplaydev_attach_args aa;
long defattr;
- int setmode, width, height;
+ int setmode = 0, width, height;
pcireg_t screg;
uint32_t reg;
const pcireg_t enables = PCI_COMMAND_MEM_ENABLE;
@@ -578,19 +497,19 @@
prop_dictionary_get_uint32(device_properties(self), "width", &width);
prop_dictionary_get_uint32(device_properties(self), "height", &height);
+ memset(&sc->sc_ei, 0, sizeof(sc->sc_ei));
if ((edid_data = prop_dictionary_get(device_properties(self), "EDID"))
!= NULL) {
- struct edid_info ei;
sc->sc_edid_size = min(1024, prop_data_size(edid_data));
memset(sc->sc_edid_data, 0, sizeof(sc->sc_edid_data));
memcpy(sc->sc_edid_data, prop_data_data_nocopy(edid_data),
sc->sc_edid_size);
- edid_parse(sc->sc_edid_data, &ei);
+ edid_parse(sc->sc_edid_data, &sc->sc_ei);
#ifdef MACHFB_DEBUG
- edid_print(&ei);
+ edid_print(&sc->sc_ei);
#endif
}
@@ -640,14 +559,19 @@
aprint_debug("using clock %d\n", sc->sc_clock);
sc->ref_div = regrb_pll(sc, PLL_REF_DIV);
- aprint_debug("ref_div: %d\n", sc->ref_div);
+ aprint_error("ref_div: %d\n", sc->ref_div);
sc->mclk_fb_div = regrb_pll(sc, MCLK_FB_DIV);
- aprint_debug("mclk_fb_div: %d\n", sc->mclk_fb_div);
+ aprint_error("mclk_fb_div: %d\n", sc->mclk_fb_div);
sc->mem_freq = (2 * sc->ref_freq * sc->mclk_fb_div) /
(sc->ref_div * 2);
sc->mclk_post_div = (sc->mclk_fb_div * 2 * sc->ref_freq) /
(sc->mem_freq * sc->ref_div);
sc->ramdac_freq = mach64_get_max_ramdac(sc);
+ {
+ sc->minref = sc->ramdac_freq / 510;
+ sc->m = sc->ref_freq / sc->minref;
+ aprint_error("minref: %d m: %d\n", sc->minref, sc->m);
+ }
aprint_normal_dev(sc->sc_dev,
"%ld KB %s %d.%d MHz, maximum RAMDAC clock %d MHz\n",
(u_long)sc->memsize,
@@ -676,34 +600,71 @@
sc->sc_console = mach64_is_console(sc);
aprint_debug("gen_cntl: %08x\n", regr(sc, CRTC_GEN_CNTL));
-#if defined(__sparc__) || defined(__powerpc__)
- if (sc->sc_console) {
- if (mode != NULL) {
+
+#define MODE_IS_VALID(m) ((sc->ramdac_freq >= (m)->dot_clock) && \
+ ((m)->hdisplay <= 11280))
+
+ /* no mode setting support on ancient chips with external clocks */
+ setmode = 0;
+ if (!is_gx) {
+ /*
+ * Now pick a mode.
+ */
+ if ((sc->sc_ei.edid_preferred_mode != NULL)) {
+ struct videomode *m = sc->sc_ei.edid_preferred_mode;
+ if (MODE_IS_VALID(m)) {
+ memcpy(&default_mode, m,
+ sizeof(struct videomode));
+ setmode = 1;
+ } else {
+ aprint_error_dev(sc->sc_dev,
+ "unable to use preferred mode\n");
+ }
+ }
+ /*
+ * if we can't use the preferred mode go look for the
+ * best one we can support
+ */
+ if (setmode == 0) {
+ struct videomode *m = sc->sc_ei.edid_modes;
+
+ mode = NULL;
+ sort_modes(sc->sc_ei.edid_modes,
+ &sc->sc_ei.edid_preferred_mode,
+ sc->sc_ei.edid_nmodes);
+ for (int n = 0; n < sc->sc_ei.edid_nmodes; n++)
+ if (MODE_IS_VALID(&m[n])) {
+ mode = &m[n];
+ break;
+ }
+ if (mode != NULL) {
+ memcpy(&default_mode, mode,
+ sizeof(struct videomode));
+ setmode = 1;
+ }
+ }
+ /* got nothing? try to pick one based on firmware parameters */
+ if (setmode == 0) {
+ /* no EDID data? */
+ mode = pick_mode_by_ref(width, height, 60);
memcpy(&default_mode, mode, sizeof(struct videomode));
setmode = 1;
- } else {
- mach64_get_mode(sc, &default_mode);
- setmode = 0;
}
- sc->sc_my_mode = &default_mode;
+ /* still nothing? Grab the default */
+ if (setmode == 0) {
+ mode = pick_mode_by_ref(1024, 768, 60);
+ memcpy(&default_mode, mode, sizeof(struct videomode));
+ setmode = 1;
+ }
} else {
- /* fill in default_mode if it's empty */
+ /* make sure my_mode points at something sensible */
mach64_get_mode(sc, &default_mode);
Home |
Main Index |
Thread Index |
Old Index