From 745387f0c4b23da05796c5e85d29b74a9eb33f3d Mon Sep 17 00:00:00 2001 From: kettenis Date: Mon, 5 Dec 2022 07:40:21 +0000 Subject: [PATCH] Add support for the Backlight connector property like we already have for inteldrm(4). This makes xbacklight(1) work when using the Xorg modesetting driver. The Xorg amdgpu driver needs a small change for this that should land soon. ok jsg@ --- sys/dev/pci/drm/amd/amdgpu/amdgpu_kms.c | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/sys/dev/pci/drm/amd/amdgpu/amdgpu_kms.c b/sys/dev/pci/drm/amd/amdgpu/amdgpu_kms.c index 27666951fed..7d8ca55e09a 100644 --- a/sys/dev/pci/drm/amd/amdgpu/amdgpu_kms.c +++ b/sys/dev/pci/drm/amd/amdgpu/amdgpu_kms.c @@ -2039,6 +2039,7 @@ amdgpu_wsioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p) case WSDISPLAYIO_PARAM_BRIGHTNESS: bd->props.brightness = dp->curval; backlight_update_status(bd); + KNOTE(&adev->ddev.note, NOTE_CHANGE); return 0; } break; @@ -2118,6 +2119,32 @@ amdgpu_enter_ddb(void *v, void *cookie) drm_fb_helper_debug_enter(fb_helper->fbdev); } +void +amdgpu_init_backlight(struct amdgpu_device *adev) +{ + struct drm_device *dev = &adev->ddev; + struct backlight_device *bd = adev->dm.backlight_dev[0]; + struct drm_connector_list_iter conn_iter; + struct drm_connector *connector; + + if (bd == NULL) + return; + + drm_connector_list_iter_begin(dev, &conn_iter); + drm_for_each_connector_iter(connector, &conn_iter) { + if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS && + connector->connector_type != DRM_MODE_CONNECTOR_eDP && + connector->connector_type != DRM_MODE_CONNECTOR_DSI) + continue; + + connector->backlight_device = bd; + connector->backlight_property = drm_property_create_range(dev, + 0, "Backlight", 0, bd->props.max_brightness); + drm_object_attach_property(&connector->base, + connector->backlight_property, bd->props.brightness); + } + drm_connector_list_iter_end(&conn_iter); +} void amdgpu_attachhook(struct device *self) @@ -2175,6 +2202,8 @@ amdgpu_attachhook(struct device *self) struct wsemuldisplaydev_attach_args aa; struct rasops_info *ri = &adev->ro; + amdgpu_init_backlight(adev); + task_set(&adev->switchtask, amdgpu_doswitch, ri); if (ri->ri_bits == NULL) -- 2.20.1