From: Mario Limonciello <[email protected]>

Expose GUD display brightness through the connector LUMINANCE property
when DRM_LUMINANCE is enabled. The value is mirrored into tv.brightness
during atomic check so it is sent to the device with
GUD_REQ_SET_STATE_CHECK in the same commit.

Signed-off-by: Mario Limonciello <[email protected]>
---
v11:
 * Apply LUMINANCE in the atomic commit instead of a worker, fixing an
   endless commit loop, a use-after-free on disconnect and brightness
   being clobbered on DPMS off (Sashiko)
 * Attach the property at connector init (Sashiko)
 * Keep selecting BACKLIGHT_CLASS_DEVICE (Sashiko)
---
 drivers/gpu/drm/gud/gud_connector.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/gud/gud_connector.c 
b/drivers/gpu/drm/gud/gud_connector.c
index ddbf3b3ebbca8..bfb298bbc9b51 100644
--- a/drivers/gpu/drm/gud/gud_connector.c
+++ b/drivers/gpu/drm/gud/gud_connector.c
@@ -292,10 +292,19 @@ static int gud_connector_atomic_check(struct 
drm_connector *connector,
        struct drm_connector_state *old_state;
 
        new_state = drm_atomic_get_new_connector_state(state, connector);
+       old_state = drm_atomic_get_old_connector_state(state, connector);
+
+       /*
+        * LUMINANCE is sent to the device as tv.brightness in the same commit,
+        * the brightness change below then triggers GUD_REQ_SET_STATE_CHECK.
+        */
+       if (connector->luminance_property &&
+           old_state->luminance != new_state->luminance)
+               new_state->tv.brightness = new_state->luminance;
+
        if (!new_state->crtc)
                return 0;
 
-       old_state = drm_atomic_get_old_connector_state(state, connector);
        new_crtc_state = drm_atomic_get_new_crtc_state(state, new_state->crtc);
 
        if (old_state->tv.margins.left != new_state->tv.margins.left ||
@@ -324,7 +333,7 @@ static int gud_connector_late_register(struct drm_connector 
*connector)
 {
        struct gud_connector *gconn = to_gud_connector(connector);
 
-       if (gconn->initial_brightness < 0)
+       if (IS_ENABLED(CONFIG_DRM_LUMINANCE) || gconn->initial_brightness < 0)
                return 0;
 
        return gud_connector_backlight_register(gconn);
@@ -699,6 +708,13 @@ static int gud_connector_create(struct gud_device *gdrm, 
unsigned int index,
                return ret;
        }
 
+       if (IS_ENABLED(CONFIG_DRM_LUMINANCE) && gconn->initial_brightness >= 0) 
{
+               ret = drm_connector_attach_luminance_property(connector, 0, 100,
+                                                             
gconn->initial_brightness);
+               if (ret)
+                       return ret;
+       }
+
        gconn->encoder.possible_crtcs = drm_crtc_mask(&gdrm->crtc);
        ret = drm_encoder_init(drm, &gconn->encoder, 
&gud_drm_simple_encoder_funcs_cleanup,
                               DRM_MODE_ENCODER_NONE, NULL);

-- 
2.53.0

Reply via email to