diff mbox

[xf86-video-intel] Add OpenBSD backlight control implementation

Message ID 1363947791-1870-1-git-send-email-mark.kettenis@xs4all.nl (mailing list archive)
State New, archived
Headers show

Commit Message

Mark Kettenis March 22, 2013, 10:23 a.m. UTC
From: Mark Kettenis <kettenis@openbsd.org>

Signed-off-by: Mark Kettenis <kettenis@openbsd.org>
---
 src/intel_display.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 69 insertions(+), 6 deletions(-)

Comments

Chris Wilson March 22, 2013, 11:30 a.m. UTC | #1
On Fri, Mar 22, 2013 at 11:23:11AM +0100, Mark Kettenis wrote:
> From: Mark Kettenis <kettenis@openbsd.org>

Thank you for the patch, I presume it works ;-)  Pushed,
-Chris
Mark Kettenis March 22, 2013, 11:02 p.m. UTC | #2
> Date: Fri, 22 Mar 2013 11:30:45 +0000
> From: Chris Wilson <chris@chris-wilson.co.uk>
> 
> On Fri, Mar 22, 2013 at 11:23:11AM +0100, Mark Kettenis wrote:
> > From: Mark Kettenis <kettenis@openbsd.org>
> 
> Thank you for the patch, I presume it works ;-)  Pushed,

It actually does work ;).  Thanks Chris!
diff mbox

Patch

diff --git a/src/intel_display.c b/src/intel_display.c
index 5ee955e..6e6a7a2 100644
--- a/src/intel_display.c
+++ b/src/intel_display.c
@@ -53,6 +53,11 @@ 
 
 #include "intel_glamor.h"
 
+#ifdef __OpenBSD__
+#include <dev/wscons/wsconsio.h>
+#include "xf86Priv.h"
+#endif
+
 #define KNOWN_MODE_FLAGS ((1<<14)-1)
 
 struct intel_mode {
@@ -127,6 +132,69 @@  intel_output_dpms(xf86OutputPtr output, int mode);
 static void
 intel_output_dpms_backlight(xf86OutputPtr output, int oldmode, int mode);
 
+static inline int
+crtc_id(struct intel_crtc *crtc)
+{
+	return crtc->mode_crtc->crtc_id;
+}
+
+#ifdef __OpenBSD__
+
+static void
+intel_output_backlight_set(xf86OutputPtr output, int level)
+{
+	struct intel_output *intel_output = output->driver_private;
+	struct wsdisplay_param param;
+
+	if (level > intel_output->backlight_max)
+		level = intel_output->backlight_max;
+	if (! intel_output->backlight_iface || level < 0)
+		return;
+
+	param.param = WSDISPLAYIO_PARAM_BRIGHTNESS;
+	param.curval = level;
+	if (ioctl(xf86Info.consoleFd, WSDISPLAYIO_SETPARAM, &param) == -1) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			   "Failed to set backlight level: %s\n",
+			   strerror(errno));
+	}
+}
+
+static int
+intel_output_backlight_get(xf86OutputPtr output)
+{
+	struct wsdisplay_param param;
+
+	param.param = WSDISPLAYIO_PARAM_BRIGHTNESS;
+	if (ioctl(xf86Info.consoleFd, WSDISPLAYIO_GETPARAM, &param) == -1) {
+		xf86DrvMsg(output->scrn->scrnIndex, X_ERROR,
+			   "Failed to get backlight level: %s\n",
+			   strerror(errno));
+		return -1;
+	}
+
+	return param.curval;
+}
+
+static void
+intel_output_backlight_init(xf86OutputPtr output)
+{
+	struct intel_output *intel_output = output->driver_private;
+	struct wsdisplay_param param;
+
+	param.param = WSDISPLAYIO_PARAM_BRIGHTNESS;
+	if (ioctl(xf86Info.consoleFd, WSDISPLAYIO_GETPARAM, &param) == -1) {
+		intel_output->backlight_iface = NULL;
+		return;
+	}
+
+	intel_output->backlight_iface = "wscons";
+	intel_output->backlight_max = param.max;
+	intel_output->backlight_active_level = param.curval;
+}
+
+#else
+
 #define BACKLIGHT_CLASS "/sys/class/backlight"
 
 /*
@@ -155,12 +223,6 @@  static const char *backlight_interfaces[] = {
 /* Enough for 10 digits of backlight + '\n' + '\0' */
 #define BACKLIGHT_VALUE_LEN 12
 
-static inline int
-crtc_id(struct intel_crtc *crtc)
-{
-	return crtc->mode_crtc->crtc_id;
-}
-
 static void
 intel_output_backlight_set(xf86OutputPtr output, int level)
 {
@@ -297,6 +359,7 @@  intel_output_backlight_init(xf86OutputPtr output)
 	intel_output->backlight_iface = NULL;
 }
 
+#endif
 
 static void
 mode_from_kmode(ScrnInfoPtr scrn,