[PATCH 1/1] drm/mgag200: Fix hardware cursor colour inversion and inaccurate register index.

Julia Lemire jlemire at matrox.com
Thu Jan 30 08:33:45 PST 2014


The hardware cursor colours are stored in the DAC indexed registers.
The algorithm for setting these colours via their corresponding index
was off by a value of 0x03.

It was also noted that the R and B bytes were being misread from the
cursor buffer.  Assuming the transparency is the MSB (bits 31-24),
then R should be bits 23-16, G should be bits 15-8 and B should be
the LSB or bits 7-0.

Signed-off-by: Julia Lemire <jlemire at matrox.com>
---
 drivers/gpu/drm/mgag200/mgag200_cursor.c |   18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/mgag200/mgag200_cursor.c b/drivers/gpu/drm/mgag200/mgag200_cursor.c
index 801731a..24463b8 100644
--- a/drivers/gpu/drm/mgag200/mgag200_cursor.c
+++ b/drivers/gpu/drm/mgag200/mgag200_cursor.c
@@ -32,7 +32,7 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
 			uint32_t width,
 			uint32_t height)
 {
-	struct drm_device *dev = (struct drm_device *)file_priv->minor->dev;
+	struct drm_device *dev = crtc->dev;
 	struct mga_device *mdev = (struct mga_device *)dev->dev_private;
 	struct mgag200_bo *pixels_1 = mdev->cursor.pixels_1;
 	struct mgag200_bo *pixels_2 = mdev->cursor.pixels_2;
@@ -45,12 +45,12 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
 	uint32_t colour_set[16];
 	uint32_t *next_space = &colour_set[0];
 	uint32_t *palette_iter;
-	uint32_t this_colour;
+	uint32_t this_colour; /* 32-bit colour encoded pixel */
 	bool found = false;
 	int colour_count = 0;
 	u64 gpu_addr;
 	u8 reg_index;
-	u8 this_row[48];
+	u8 this_row[48]; /* cursor bitmap row array */
 
 	if (!pixels_1 || !pixels_2) {
 		WREG8(MGA_CURPOSXL, 0);
@@ -171,14 +171,20 @@ int mga_crtc_cursor_set(struct drm_crtc *crtc,
 	}
 
 	/* Program colours from cursor icon into palette */
+	/* Colour is received as RGB, where R are the MSB and B are the LSB. */
+	/* The first three colours are located between indexes 0x08-0x12. */
+	/* The remaining colours are located between indexes 0x60-0x86. */
 	for (i = 0; i < colour_count; i++) {
 		if (i <= 2)
 			reg_index = 0x8 + i*0x4;
 		else
-			reg_index = 0x60 + i*0x3;
-		WREG_DAC(reg_index, colour_set[i] & 0xff);
+			reg_index = 0x60 + (i-3)*0x3;
+		/* Write the Red bits. */
+		WREG_DAC(reg_index, colour_set[i]>>16 & 0xff);
+		/* Write the Green bits. */
 		WREG_DAC(reg_index+1, colour_set[i]>>8 & 0xff);
-		WREG_DAC(reg_index+2, colour_set[i]>>16 & 0xff);
+		/* Write the Blue bits. */
+		WREG_DAC(reg_index+2, colour_set[i] & 0xff);
 		BUG_ON((colour_set[i]>>24 & 0xff) != 0xff);
 	}
 
-- 
1.7.10.4



More information about the dri-devel mailing list