Module Name:    src
Committed By:   macallan
Date:           Thu Jul 23 07:21:45 UTC 2009

Modified Files:
        src/sys/dev/pci: radeonfb.c

Log Message:
quick hack to allow brightness control via PMF


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/sys/dev/pci/radeonfb.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/dev/pci/radeonfb.c
diff -u src/sys/dev/pci/radeonfb.c:1.33 src/sys/dev/pci/radeonfb.c:1.34
--- src/sys/dev/pci/radeonfb.c:1.33	Tue May 12 08:23:01 2009
+++ src/sys/dev/pci/radeonfb.c	Thu Jul 23 07:21:45 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: radeonfb.c,v 1.33 2009/05/12 08:23:01 cegger Exp $ */
+/*	$NetBSD: radeonfb.c,v 1.34 2009/07/23 07:21:45 macallan Exp $ */
 
 /*-
  * Copyright (c) 2006 Itronix Inc.
@@ -70,7 +70,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v 1.33 2009/05/12 08:23:01 cegger Exp $");
+__KERNEL_RCSID(0, "$NetBSD: radeonfb.c,v 1.34 2009/07/23 07:21:45 macallan Exp $");
 
 #define RADEONFB_DEFAULT_DEPTH 32
 
@@ -169,6 +169,9 @@
 static int radeonfb_set_backlight(struct radeonfb_display *, int);
 static void radeonfb_lvds_callout(void *);
 
+static void radeonfb_brightness_up(device_t);
+static void radeonfb_brightness_down(device_t);
+
 static struct videomode *radeonfb_best_refresh(struct videomode *,
     struct videomode *);
 static void radeonfb_pickres(struct radeonfb_display *, uint16_t *,
@@ -431,7 +434,7 @@
 	const char		*mptr;
 	bus_size_t		bsz;
 	pcireg_t		screg;
-	int			i, j, fg, bg, ul;
+	int			i, j, fg, bg, ul, flags;
 	uint32_t		v;
 
 	sc->sc_id = pa->pa_id;
@@ -529,6 +532,14 @@
 		goto error;
 	}
 
+	if (pci_mapreg_info(sc->sc_pc, sc->sc_pt, PCI_MAPREG_ROM,
+	     PCI_MAPREG_TYPE_ROM, &sc->sc_romaddr, &sc->sc_romsz, &flags) != 0)
+	{
+		aprint_error("%s: unable to find ROM!\n", XNAME(sc));
+		goto error;
+	}
+	sc->sc_romt = sc->sc_memt;
+
 	/* scratch register test... */
 	if (radeonfb_scratch_test(sc, RADEON_BIOS_0_SCRATCH, 0x55555555) ||
 	    radeonfb_scratch_test(sc, RADEON_BIOS_0_SCRATCH, 0xaaaaaaaa)) {
@@ -810,7 +821,9 @@
 
 		dp->rd_vd.init_screen = radeonfb_init_screen;
 
-		dp->rd_console = 1;
+		dp->rd_console = 0;
+		prop_dictionary_get_bool(device_properties(&sc->sc_dev),
+		    "is_console", &dp->rd_console);
 
 		dp->rd_vscreen.scr_flags |= VCONS_SCREEN_IS_STATIC;
 
@@ -892,6 +905,11 @@
 				radeonfb_lvds_callout, dp);
 	}
 
+	pmf_event_register(dev, PMFE_DISPLAY_BRIGHTNESS_UP,
+	    radeonfb_brightness_up, TRUE);
+	pmf_event_register(dev, PMFE_DISPLAY_BRIGHTNESS_DOWN,
+	    radeonfb_brightness_down, TRUE);
+
 	config_found_ia(dev, "drm", aux, radeonfb_drm_print);
 
 	return;
@@ -982,7 +1000,7 @@
 			if ((dp->rd_wsmode == WSDISPLAYIO_MODE_EMUL) &&
 			    (dp->rd_vd.active)) {
 				radeonfb_engine_init(dp);
-				radeonfb_modeswitch(dp);
+				//radeonfb_modeswitch(dp);
 				vcons_redraw_screen(dp->rd_vd.active);
 			}
 		}
@@ -1069,7 +1087,6 @@
 
 	/* XXX: note that we don't allow mapping of registers right now */
 	/* XXX: this means that the XFree86 radeon driver won't work */
-
 	if ((offset >= 0) && (offset < (dp->rd_virty * dp->rd_stride))) {
 		pa = bus_space_mmap(sc->sc_memt,
 		    sc->sc_memaddr + dp->rd_offset + offset, 0,
@@ -1100,6 +1117,12 @@
 		    BUS_SPACE_MAP_LINEAR);
 	}
 
+	if ((offset >= sc->sc_romaddr) && 
+	    (offset < sc->sc_romaddr + sc->sc_romsz)) {
+		return bus_space_mmap(sc->sc_memt, offset, 0, prot, 
+		    BUS_SPACE_MAP_LINEAR);
+	}
+
 #ifdef PCI_MAGIC_IO_RANGE
 	/* allow mapping of IO space */
 	if ((offset >= PCI_MAGIC_IO_RANGE) &&
@@ -3505,3 +3528,29 @@
 
 	splx(s);
 }
+
+static void
+radeonfb_brightness_up(device_t dev)
+{
+	struct radeonfb_softc *sc = device_private(dev);
+	int level;
+
+	/* we assume the main display is the first one - need a better way */
+	if (sc->sc_ndisplays < 1) return;
+	level = radeonfb_get_backlight(&sc->sc_displays[0]);
+	level = min(RADEONFB_BACKLIGHT_MAX, level + 5);
+	radeonfb_set_backlight(&sc->sc_displays[0], level);
+}
+
+static void
+radeonfb_brightness_down(device_t dev)
+{
+	struct radeonfb_softc *sc = device_private(dev);
+	int level;
+
+	/* we assume the main display is the first one - need a better way */
+	if (sc->sc_ndisplays < 1) return;
+	level = radeonfb_get_backlight(&sc->sc_displays[0]);
+	level = max(0, level - 5);
+	radeonfb_set_backlight(&sc->sc_displays[0], level);
+}

Reply via email to