Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/pci add backlight control via PMF
details: https://anonhg.NetBSD.org/src/rev/e2a7daacca08
branches: trunk
changeset: 757639:e2a7daacca08
user: macallan <macallan%NetBSD.org@localhost>
date: Thu Sep 09 01:22:10 2010 +0000
description:
add backlight control via PMF
TODO: support wsconsctl
diffstat:
sys/dev/pci/r128fb.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++--
sys/dev/pci/r128fbreg.h | 32 ++++++++++++++++++++--
2 files changed, 94 insertions(+), 7 deletions(-)
diffs (169 lines):
diff -r 5ecc53818518 -r e2a7daacca08 sys/dev/pci/r128fb.c
--- a/sys/dev/pci/r128fb.c Thu Sep 09 00:24:59 2010 +0000
+++ b/sys/dev/pci/r128fb.c Thu Sep 09 01:22:10 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: r128fb.c,v 1.10 2009/10/01 19:02:27 jmmv Exp $ */
+/* $NetBSD: r128fb.c,v 1.11 2010/09/09 01:22:11 macallan Exp $ */
/*
* Copyright (c) 2007 Michael Lorenz
@@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: r128fb.c,v 1.10 2009/10/01 19:02:27 jmmv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: r128fb.c,v 1.11 2010/09/09 01:22:11 macallan Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -59,6 +59,14 @@
#include <dev/i2c/i2cvar.h>
+#include "opt_r128fb.h"
+
+#ifdef R128FB_DEBUG
+#define DPRINTF printf
+#else
+#define DPRINTF while(0) printf
+#endif
+
struct r128fb_softc {
device_t sc_dev;
@@ -74,7 +82,7 @@
bus_size_t sc_fbsize, sc_regsize;
int sc_width, sc_height, sc_depth, sc_stride;
- int sc_locked;
+ int sc_locked, sc_have_backlight, sc_bl_level;
void *sc_fbaddr;
struct vcons_screen sc_console_screen;
struct wsscreen_descr sc_defaultscreen_descr;
@@ -124,6 +132,10 @@
static void r128fb_copyrows(void *, int, int, int);
static void r128fb_eraserows(void *, int, int, long);
+static void r128fb_brightness_up(device_t);
+static void r128fb_brightness_down(device_t);
+static void r128fb_set_backlight(struct r128fb_softc *, int);
+
struct wsdisplay_accessops r128fb_accessops = {
r128fb_ioctl,
r128fb_mmap,
@@ -191,6 +203,7 @@
unsigned long defattr;
bool is_console;
int i, j;
+ uint32_t reg;
sc->sc_pc = pa->pa_pc;
sc->sc_pcitag = pa->pa_tag;
@@ -305,7 +318,21 @@
aa.accesscookie = &sc->vd;
config_found(sc->sc_dev, &aa, wsemuldisplaydevprint);
-
+
+ /* no suspend/resume support yet */
+ pmf_device_register(sc->sc_dev, NULL, NULL);
+ reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, R128_LVDS_GEN_CNTL);
+ DPRINTF("reg: %08x\n", reg);
+ if (reg & R128_LVDS_ON) {
+ sc->sc_have_backlight = 1;
+ sc->sc_bl_level = 255 -
+ ((reg & R128_LEVEL_MASK) >> R128_LEVEL_SHIFT);
+ pmf_event_register(sc->sc_dev, PMFE_DISPLAY_BRIGHTNESS_UP,
+ r128fb_brightness_up, TRUE);
+ pmf_event_register(sc->sc_dev, PMFE_DISPLAY_BRIGHTNESS_DOWN,
+ r128fb_brightness_down, TRUE);
+ } else
+ sc->sc_have_backlight = 0;
}
static int
@@ -787,3 +814,37 @@
}
}
+static void
+r128fb_set_backlight(struct r128fb_softc *sc, int level)
+{
+ uint32_t reg;
+
+ if (level > 255) level = 255;
+ if (level < 0) level = 0;
+ if (level == sc->sc_bl_level)
+ return;
+ sc->sc_bl_level = level;
+ level = 255 - level;
+ reg = bus_space_read_4(sc->sc_memt, sc->sc_regh, R128_LVDS_GEN_CNTL);
+ reg &= ~R128_LEVEL_MASK;
+ reg |= level << R128_LEVEL_SHIFT;
+ bus_space_write_4(sc->sc_memt, sc->sc_regh, R128_LVDS_GEN_CNTL, reg);
+ DPRINTF("level: %d reg %08x\n", level, reg);
+}
+
+
+static void
+r128fb_brightness_up(device_t dev)
+{
+ struct r128fb_softc *sc = device_private(dev);
+
+ r128fb_set_backlight(sc, sc->sc_bl_level + 8);
+}
+
+static void
+r128fb_brightness_down(device_t dev)
+{
+ struct r128fb_softc *sc = device_private(dev);
+
+ r128fb_set_backlight(sc, sc->sc_bl_level - 8);
+}
diff -r 5ecc53818518 -r e2a7daacca08 sys/dev/pci/r128fbreg.h
--- a/sys/dev/pci/r128fbreg.h Thu Sep 09 00:24:59 2010 +0000
+++ b/sys/dev/pci/r128fbreg.h Thu Sep 09 01:22:10 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: r128fbreg.h,v 1.1 2007/11/07 19:09:09 macallan Exp $ */
+/* $NetBSD: r128fbreg.h,v 1.2 2010/09/09 01:22:10 macallan Exp $ */
/*
* Copyright 1999, 2000 ATI Technologies Inc., Markham, Ontario,
@@ -55,9 +55,35 @@
#ifndef R128FB_REG_H
#define R128FB_REG_H
-#define R128_PALETTE_DATA 0x00b4
-#define R128_PALETTE_INDEX 0x00b0
+/* RAMDAC */
+#define R128_PALETTE_DATA 0x00b4
+#define R128_PALETTE_INDEX 0x00b0
+/* flat panel registers */
+#define R128_FP_PANEL_CNTL 0x0288
+ #define FPCNT_DIGON 0x00000001 /* FP dig. voltage */
+ #define FPCNT_BACKLIGHT_ON 0x00000002
+ #define FPCNT_BL_MODULATION_ON 0x00000004
+ #define FPCNT_BL_CLK_SEL 0x00000008 /* 1 - divide by 3 */
+ #define FPCNT_MONID_EN 0x00000010 /* use MONID pins for
+ backlight control */
+ #define FPCNT_FPENABLE_POL 0x00000020 /* 1 - active low */
+ #define FPCNT_LEVEL_MASK 0x0000ff00
+ #define FPCNT_LEVEL_SHIFT 8
+
+#define R128_LVDS_GEN_CNTL 0x02d0
+# define R128_LVDS_ON (1 << 0)
+# define R128_LVDS_DISPLAY_DIS (1 << 1)
+# define R128_LVDS_EN (1 << 7)
+# define R128_LVDS_DIGON (1 << 18)
+# define R128_LVDS_BLON (1 << 19)
+# define R128_LVDS_SEL_CRTC2 (1 << 23)
+# define R128_HSYNC_DELAY_SHIFT 28
+# define R128_HSYNC_DELAY_MASK (0xf << 28)
+# define R128_LEVEL_MASK 0x0000ff00
+# define R128_LEVEL_SHIFT 8
+
+/* drawing engine */
#define R128_PC_NGUI_CTLSTAT 0x0184
# define R128_PC_FLUSH_GUI (3 << 0)
# define R128_PC_RI_GUI (1 << 2)
Home |
Main Index |
Thread Index |
Old Index