Hi,
i am trying to get backlight and brightness control running on my
Powerbook G4. Both can be controlled via ofw.
The vgafb(4) video driver currently directly calls of_setbrightness() directly
instead of relying on wscons, DRM users are out of luck.
The diff below wires the ofw backlight commands to ws_get_param/ws_set_param
and makes wsconsctl backlight/brightness work on my machine using radeondrm.
ok?
Index: ofw_machdep.c
===================================================================
RCS file: /cvs/src/sys/arch/macppc/macppc/ofw_machdep.c,v
retrieving revision 1.59
diff -u -p -r1.59 ofw_machdep.c
--- ofw_machdep.c 25 May 2020 09:55:48 -0000 1.59
+++ ofw_machdep.c 26 Oct 2020 17:04:48 -0000
@@ -61,6 +61,7 @@
#endif
#if NWSDISPLAY > 0
+#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/rasops/rasops.h>
#endif
@@ -108,6 +109,9 @@ int save_ofw_mapping(void);
void ofw_consinit(int);
void ofw_read_mem_regions(int, int, int);
+int ofw_set_param(struct wsdisplay_param *);
+int ofw_get_param(struct wsdisplay_param *);
+
/*
* This is called during initppc, before the system is really initialized.
* It shall provide the total and the available regions of RAM.
@@ -267,6 +271,7 @@ save_ofw_mapping(void)
}
static int display_ofh;
+int cons_backlight;
int cons_brightness;
int cons_backlight_available;
int fbnode;
@@ -472,6 +477,11 @@ of_display_console(void)
if (OF_getnodebyname(0, "backlight") != 0) {
cons_backlight_available = 1;
cons_brightness = MAX_BRIGHTNESS;
+ cons_backlight = WSDISPLAYIO_VIDEO_ON;
+
+ /* wsconsctl hooks */
+ ws_get_param = ofw_get_param;
+ ws_set_param = ofw_set_param;
}
#if 1
@@ -536,6 +546,8 @@ of_setbacklight(int on)
if (cons_backlight_available == 0)
return;
+ cons_backlight = on;
+
if (on)
OF_call_method_1("backlight-on", display_ofh, 0);
else
@@ -637,3 +649,53 @@ ofw_consinit(int chosen)
cn_tab = cp;
}
+int
+ofw_set_param(struct wsdisplay_param *dp)
+{
+ switch (dp->param) {
+ case WSDISPLAYIO_PARAM_BRIGHTNESS:
+ if (cons_backlight_available != 0) {
+ of_setbrightness(dp->curval);
+ return 0;
+ }
+ break;
+ case WSDISPLAYIO_PARAM_BACKLIGHT:
+ if (cons_backlight_available != 0) {
+ of_setbacklight(dp->curval ? WSDISPLAYIO_VIDEO_ON
+ : WSDISPLAYIO_VIDEO_OFF);
+ return 0;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return -1;
+}
+
+int
+ofw_get_param(struct wsdisplay_param *dp)
+{
+ switch (dp->param) {
+ case WSDISPLAYIO_PARAM_BRIGHTNESS:
+ if (cons_backlight_available != 0) {
+ dp->min = MIN_BRIGHTNESS;
+ dp->max = MAX_BRIGHTNESS;
+ dp->curval = cons_brightness;
+ return 0;
+ }
+ break;
+ case WSDISPLAYIO_PARAM_BACKLIGHT:
+ if (cons_backlight_available != 0) {
+ dp->min = 0;
+ dp->max = 1;
+ dp->curval = cons_backlight;
+ return 0;
+ }
+ break;
+ default:
+ break;
+ }
+
+ return 1;
+}