backlight control and console detection for wsdisplay systems

based on a patch by Michael Lorenz.

Signed-off-by: Nia Alarie <nia@NetBSD.org>
Part-of: <https://gitlab.freedesktop.org/xorg/driver/xf86-video-r128/-/merge_requests/7>
This commit is contained in:
nia
2024-05-06 01:14:34 +02:00
parent 09ca76bf1d
commit f753d699fd
3 changed files with 80 additions and 5 deletions

View File

@@ -310,6 +310,7 @@ typedef struct {
#ifdef HAVE_DEV_WSCONS_WSCONSIO_H
Bool HaveWSDisplay;
Bool HaveBacklightControl;
#endif
unsigned long LinearAddr; /* Frame buffer physical address */

View File

@@ -115,7 +115,6 @@
#include <X11/extensions/dpms.h>
#endif
static Bool R128CloseScreen(CLOSE_SCREEN_ARGS_DECL);
static Bool R128SaveScreen(ScreenPtr pScreen, int mode);
static void R128Save(ScrnInfoPtr pScrn);
@@ -1455,6 +1454,9 @@ R128PreInitAccel(ScrnInfoPtr pScrn)
Bool R128PreInit(ScrnInfoPtr pScrn, int flags)
{
R128InfoPtr info;
#ifdef WSDISPLAYIO_GET_BUSID
struct wsdisplayio_bus_id bid;
#endif
DEBUG(xf86DrvMsg(pScrn->scrnIndex, X_INFO,
"%s\n", __func__));
@@ -1492,6 +1494,29 @@ Bool R128PreInit(ScrnInfoPtr pScrn, int flags)
PCI_DEV_DEV(info->PciInfo),
PCI_DEV_FUNC(info->PciInfo));
#ifdef WSDISPLAYIO_GET_BUSID
/* now check if this is the console */
info->HaveWSDisplay = FALSE;
info->HaveBacklightControl = FALSE;
if (ioctl(xf86Info.consoleFd, WSDISPLAYIO_GET_BUSID, &bid) != -1) {
if ((bid.bus_type == WSDISPLAYIO_BUS_PCI) &&
(bid.ubus.pci.bus == PCI_DEV_BUS(info->PciInfo)) &&
(bid.ubus.pci.device == PCI_DEV_DEV(info->PciInfo)) &&
(bid.ubus.pci.function == PCI_DEV_FUNC(info->PciInfo))) {
struct wsdisplay_param p;
info->HaveWSDisplay = TRUE;
#ifdef WSDISPLAYIO_PARAM_BACKLIGHT
/* now see if we have hacklight control */
p.param = WSDISPLAYIO_PARAM_BACKLIGHT;
if (ioctl(xf86Info.consoleFd, WSDISPLAYIO_GETPARAM, &p) != -1) {
info->HaveBacklightControl = TRUE;
}
#endif
}
}
#endif
#ifndef XSERVER_LIBPCIACCESS
info->PciTag = pciTag(PCI_DEV_BUS(info->PciInfo),
PCI_DEV_DEV(info->PciInfo),

View File

@@ -33,8 +33,15 @@
#include <string.h>
#include <stdio.h>
#ifdef HAVE_DEV_WSCONS_WSCONSIO_H
#include <sys/ioctl.h>
#include <dev/wscons/wsconsio.h>
#endif
#include "xf86.h"
#include "xf86Modes.h"
#include "xf86Priv.h"
#include "xf86Privstr.h"
#ifdef HAVE_XEXTPROTO_71
#include "X11/extensions/dpmsconst.h"
@@ -211,9 +218,20 @@ void R128DPMSSetOn(xf86OutputPtr output)
switch(MonType) {
case MT_LCD:
OUTREGP(R128_LVDS_GEN_CNTL, R128_LVDS_BLON, ~R128_LVDS_BLON);
usleep(r128_output->PanelPwrDly * 1000);
OUTREGP(R128_LVDS_GEN_CNTL, R128_LVDS_ON, ~R128_LVDS_ON);
#ifdef WSDISPLAYIO_PARAM_BACKLIGHT
if (info->HaveBacklightControl) {
struct wsdisplay_param p;
p.param = WSDISPLAYIO_PARAM_BACKLIGHT;
p.curval = 1;
ioctl(xf86Info.consoleFd, WSDISPLAYIO_SETPARAM, &p);
} else
#endif
{
OUTREGP(R128_LVDS_GEN_CNTL, R128_LVDS_BLON, ~R128_LVDS_BLON);
usleep(r128_output->PanelPwrDly * 1000);
OUTREGP(R128_LVDS_GEN_CNTL, R128_LVDS_ON, ~R128_LVDS_ON);
}
save->lvds_gen_cntl |= (R128_LVDS_ON | R128_LVDS_BLON);
break;
case MT_DFP:
@@ -240,7 +258,18 @@ void R128DPMSSetOff(xf86OutputPtr output)
switch(MonType) {
case MT_LCD:
OUTREGP(R128_LVDS_GEN_CNTL, 0, ~(R128_LVDS_BLON | R128_LVDS_ON));
#ifdef WSDISPLAYIO_PARAM_BACKLIGHT
if (info->HaveBacklightControl) {
struct wsdisplay_param p;
p.param = WSDISPLAYIO_PARAM_BACKLIGHT;
p.curval = 0;
ioctl(xf86Info.consoleFd, WSDISPLAYIO_SETPARAM, &p);
} else
#endif
{
OUTREGP(R128_LVDS_GEN_CNTL, 0, ~(R128_LVDS_BLON | R128_LVDS_ON));
}
save->lvds_gen_cntl &= ~(R128_LVDS_BLON | R128_LVDS_ON);
break;
case MT_DFP:
@@ -269,6 +298,26 @@ static R128MonitorType R128DisplayDDCConnected(xf86OutputPtr output)
uint32_t mask1, mask2;
if (r128_output->type == OUTPUT_LVDS) {
#ifdef WSDISPLAYIO_GET_EDID
if (info->HaveWSDisplay) {
struct wsdisplayio_edid_info ei;
char *buffer;
xf86MonPtr tmp;
buffer = malloc(1024);
ei.edid_data = buffer;
ei.buffer_size = 1024;
if (ioctl(xf86Info.consoleFd, WSDISPLAYIO_GET_EDID, &ei) != -1) {
xf86Msg(X_INFO, "got %d bytes worth of EDID from wsdisplay\n",
ei.data_size);
tmp = xf86InterpretEEDID(pScrn->scrnIndex, buffer);
tmp->flags |= MONITOR_EDID_COMPLETE_RAWDATA;
*MonInfo = tmp;
xf86OutputSetEDID(output, tmp);
} else
free(buffer);
}
#endif
return MT_LCD;
} else if (r128_output->type == OUTPUT_VGA) {
mask1 = R128_GPIO_MONID_MASK_1 | (pR128Ent->HasCRTC2 ? R128_GPIO_MONID_MASK_3 : R128_GPIO_MONID_MASK_2);