All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jocelyn Falempe <jfalempe@redhat.com>
To: dri-devel@lists.freedesktop.org, lyude@redhat.com, tzimmermann@suse.de
Cc: michel@daenzer.net, Jocelyn Falempe <jfalempe@redhat.com>
Subject: [PATCH] mgag200: Enable atomic gamma lut update
Date: Mon,  9 May 2022 11:49:30 +0200	[thread overview]
Message-ID: <20220509094930.44613-1-jfalempe@redhat.com> (raw)

Add support for atomic update of gamma lut.
With this patch the "Night light" feature of gnome3
is working properly on mgag200.

Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
---
 drivers/gpu/drm/mgag200/mgag200_mode.c | 46 ++++++++++++++++++++++++++
 1 file changed, 46 insertions(+)

diff --git a/drivers/gpu/drm/mgag200/mgag200_mode.c b/drivers/gpu/drm/mgag200/mgag200_mode.c
index 6e18d3bbd720..9fc688e15db8 100644
--- a/drivers/gpu/drm/mgag200/mgag200_mode.c
+++ b/drivers/gpu/drm/mgag200/mgag200_mode.c
@@ -86,6 +86,46 @@ static void mga_crtc_load_lut(struct drm_crtc *crtc)
 	}
 }
 
+static void mga_crtc_update_lut(struct mga_device *mdev,
+				struct drm_crtc_state *state,
+				u8 depth)
+{
+	struct drm_color_lut * lut;
+	int i;
+	
+	if (!state->color_mgmt_changed || !state->gamma_lut)
+		return
+
+	lut = (struct drm_color_lut *) state->gamma_lut->data;
+	WREG8(DAC_INDEX + MGA1064_INDEX, 0);
+
+	if (depth == 15) {
+		/* 16 bits r5g5b5a1 */
+		for (i = 0; i < MGAG200_LUT_SIZE; i += 8) {
+			WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].red >> 8);
+			WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].green >> 8);
+			WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].blue >> 8);
+		}
+	} else if (depth == 16) {
+		/* 16 bits r5g6b5, as green has one more bit, 
+		 * add padding with 0 for red and blue. */
+		for (i = 0; i < MGAG200_LUT_SIZE; i += 4) {
+			u8 red = 2 * i < MGAG200_LUT_SIZE ? lut[2 * i].red >> 8 : 0;
+			u8 blue = 2 * i < MGAG200_LUT_SIZE ? lut[2 * i].red >> 8 : 0;
+			WREG8(DAC_INDEX + MGA1064_COL_PAL, red);
+			WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].green >> 8);
+			WREG8(DAC_INDEX + MGA1064_COL_PAL, blue);
+		}
+	} else {
+		/* 24 bits r8g8b8 */
+		for (i = 0; i < MGAG200_LUT_SIZE; i++) {
+			WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].red >> 8);
+			WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].green >> 8);
+			WREG8(DAC_INDEX + MGA1064_COL_PAL, lut[i].blue >> 8);
+		}
+	}
+}
+
 static inline void mga_wait_vsync(struct mga_device *mdev)
 {
 	unsigned long timeout = jiffies + HZ/10;
@@ -953,6 +993,7 @@ mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe,
 				   struct drm_plane_state *old_state)
 {
 	struct drm_plane *plane = &pipe->plane;
+	struct drm_crtc *crtc = &pipe->crtc;
 	struct drm_device *dev = plane->dev;
 	struct mga_device *mdev = to_mga_device(dev);
 	struct drm_plane_state *state = plane->state;
@@ -963,7 +1004,10 @@ mgag200_simple_display_pipe_update(struct drm_simple_display_pipe *pipe,
 	if (!fb)
 		return;
 
+	mga_crtc_update_lut(mdev, crtc->state, fb->format->depth);
+
 	if (drm_atomic_helper_damage_merged(old_state, state, &damage))
+
 		mgag200_handle_damage(mdev, fb, &damage, &shadow_plane_state->data[0]);
 }
 
@@ -1110,6 +1154,8 @@ int mgag200_modeset_init(struct mga_device *mdev)
 	/* FIXME: legacy gamma tables; convert to CRTC state */
 	drm_mode_crtc_set_gamma_size(&pipe->crtc, MGAG200_LUT_SIZE);
 
+	drm_crtc_enable_color_mgmt(&pipe->crtc, 0, false, MGAG200_LUT_SIZE);
+
 	drm_mode_config_reset(dev);
 
 	return 0;
-- 
2.35.3


             reply	other threads:[~2022-05-09  9:50 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-05-09  9:49 Jocelyn Falempe [this message]
2022-05-09 14:22 ` [PATCH] mgag200: Enable atomic gamma lut update Thomas Zimmermann
2022-05-09 15:43   ` Jocelyn Falempe
2022-05-10  7:13     ` Thomas Zimmermann
2022-05-09 16:04   ` Michel Dänzer
2022-05-09 21:00     ` Jocelyn Falempe
2022-05-10  6:58       ` Thomas Zimmermann
2022-05-09 21:37 ` kernel test robot
2022-05-09 21:37   ` kernel test robot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220509094930.44613-1-jfalempe@redhat.com \
    --to=jfalempe@redhat.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lyude@redhat.com \
    --cc=michel@daenzer.net \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.