Skip to contentSkip to conversation

drm/mgag200: Fix color formats

PATCH In review Thomas Zimmermann 2 participants 15 messages Apr 15 – Apr 16

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

cover drm/mgag200: Fix color formats

Fix various issues with mgag200's handlign of color formats. Remove the deprecated cpp field, simplify the code and add missing formats.

Tested on a G200 card by running the framebuffer console and Xorg with the different color formats; as far as they support them.

Thomas Zimmermann (6):
drm/mgag200: Set xmulctrl from DRM format drm/mgag200: Set scale from DRM format drm/mgag200: Simplify offset calculation drm/mgag200: g200se: Set hiprilvl from DRM format drm/mgag200: Enable DRM_FORMAT_C8 on the primary plane drm/mgag200: Enable DRM_FORMAT_XRGB1555 on the primary plane

 drivers/gpu/drm/mgag200/mgag200_g200se.c | 13 +++-
 drivers/gpu/drm/mgag200/mgag200_mode.c   | 99 +++++++++++-------------
 drivers/gpu/drm/mgag200/mgag200_reg.h    |  1 +
 3 files changed, 55 insertions(+), 58 deletions(-)
Signature · 1 line
2.53.0
author maintainer
#1 lore raw

PATCH 1/6 drm/mgag200: Set xmulctrl from DRM format

Replace the deprecated cpp value from struct drm_format_info with the format's 4CC code when setting the depth value in the XMULCTRL register. Split the 16-bit case into XRGB1555 and RGB565. The default branch cannot be taken, so remove it.

---
 drivers/gpu/drm/mgag200/mgag200_mode.c | 26 +++++++++++---------------
 1 file changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +11 -15
index 8894a063b1a1..316413d814ae 100644
@@ -343,9 +343,9 @@ static void mgag200_set_offset(struct mga_device *mdev,
 
 void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_info *format)
 {
-	struct drm_device *dev = &mdev->base;
 	unsigned int bpp, bppshift, scale;
-	u8 crtcext3, xmulctrl;
+	u8 xmulctrl = 0;
+	u8 crtcext3;
 
 	bpp = format->cpp[0] * 8;
 
@@ -361,26 +361,22 @@ void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_in
 
 	RREG_ECRT(3, crtcext3);
 
-	switch (bpp) {
-	case 8:
+	switch (format->format) {
+	case DRM_FORMAT_C8:
 		xmulctrl = MGA1064_MUL_CTL_8bits;
 		break;
-	case 16:
-		if (format->depth == 15)
-			xmulctrl = MGA1064_MUL_CTL_15bits;
-		else
-			xmulctrl = MGA1064_MUL_CTL_16bits;
+	case DRM_FORMAT_XRGB1555:
+		xmulctrl = MGA1064_MUL_CTL_15bits;
 		break;
-	case 24:
+	case DRM_FORMAT_RGB565:
+		xmulctrl = MGA1064_MUL_CTL_16bits;
+		break;
+	case DRM_FORMAT_RGB888:
 		xmulctrl = MGA1064_MUL_CTL_24bits;
 		break;
-	case 32:
+	case DRM_FORMAT_XRGB8888:
 		xmulctrl = MGA1064_MUL_CTL_32_24bits;
 		break;
-	default:
-		/* BUG: We should have caught this problem already. */
-		drm_WARN_ON(dev, "invalid format depth\n");
-		return;
 	}
 
 	crtcext3 &= ~GENMASK(2, 0);
Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 1/6
#2 lore raw

Re: [PATCH 1/6] drm/mgag200: Set xmulctrl from DRM format

Quoted 4 lines · Thomas Zimmermann

Replace the deprecated cpp value from struct drm_format_info with the format's 4CC code when setting the depth value in the XMULCTRL register. Split the 16-bit case into XRGB1555 and RGB565. The default branch cannot be taken, so remove it.

Thanks, it looks good to me.

Quoted 58 lines
---
  drivers/gpu/drm/mgag200/mgag200_mode.c | 26 +++++++++++---------------
  1 file changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +11 -15
index 8894a063b1a1..316413d814ae 100644
@@ -343,9 +343,9 @@ static void mgag200_set_offset(struct mga_device *mdev,
 
  void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_info *format)
  {
-	struct drm_device *dev = &mdev->base;
  	unsigned int bpp, bppshift, scale;
-	u8 crtcext3, xmulctrl;
+	u8 xmulctrl = 0;
+	u8 crtcext3;
 
  	bpp = format->cpp[0] * 8;
 
@@ -361,26 +361,22 @@ void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_in
 
  	RREG_ECRT(3, crtcext3);
 
-	switch (bpp) {
-	case 8:
+	switch (format->format) {
+	case DRM_FORMAT_C8:
  		xmulctrl = MGA1064_MUL_CTL_8bits;
  		break;
-	case 16:
-		if (format->depth == 15)
-			xmulctrl = MGA1064_MUL_CTL_15bits;
-		else
-			xmulctrl = MGA1064_MUL_CTL_16bits;
+	case DRM_FORMAT_XRGB1555:
+		xmulctrl = MGA1064_MUL_CTL_15bits;
  		break;
-	case 24:
+	case DRM_FORMAT_RGB565:
+		xmulctrl = MGA1064_MUL_CTL_16bits;
+		break;
+	case DRM_FORMAT_RGB888:
  		xmulctrl = MGA1064_MUL_CTL_24bits;
  		break;
-	case 32:
+	case DRM_FORMAT_XRGB8888:
  		xmulctrl = MGA1064_MUL_CTL_32_24bits;
  		break;
-	default:
-		/* BUG: We should have caught this problem already. */
-		drm_WARN_ON(dev, "invalid format depth\n");
-		return;
  	}
 
  	crtcext3 &= ~GENMASK(2, 0);
reviewer Reviewed-by on v1 1/6
#3 lore raw

Re: [PATCH 1/6] drm/mgag200: Set xmulctrl from DRM format

In reply to Thomas Zimmermann
Quoted 5 lines · Thomas Zimmermann

Replace the deprecated cpp value from struct drm_format_info with the format's 4CC code when setting the depth value in the XMULCTRL register. Split the 16-bit case into XRGB1555 and RGB565. The default branch cannot be taken, so remove it.

Thanks, it looks good to me.

Quoted 57 lines
---
  drivers/gpu/drm/mgag200/mgag200_mode.c | 26 +++++++++++---------------
  1 file changed, 11 insertions(+), 15 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +11 -15
index 8894a063b1a1..316413d814ae 100644
@@ -343,9 +343,9 @@ static void mgag200_set_offset(struct mga_device *mdev,
 
  void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_info *format)
  {
-	struct drm_device *dev = &mdev->base;
  	unsigned int bpp, bppshift, scale;
-	u8 crtcext3, xmulctrl;
+	u8 xmulctrl = 0;
+	u8 crtcext3;
 
  	bpp = format->cpp[0] * 8;
 
@@ -361,26 +361,22 @@ void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_in
 
  	RREG_ECRT(3, crtcext3);
 
-	switch (bpp) {
-	case 8:
+	switch (format->format) {
+	case DRM_FORMAT_C8:
  		xmulctrl = MGA1064_MUL_CTL_8bits;
  		break;
-	case 16:
-		if (format->depth == 15)
-			xmulctrl = MGA1064_MUL_CTL_15bits;
-		else
-			xmulctrl = MGA1064_MUL_CTL_16bits;
+	case DRM_FORMAT_XRGB1555:
+		xmulctrl = MGA1064_MUL_CTL_15bits;
  		break;
-	case 24:
+	case DRM_FORMAT_RGB565:
+		xmulctrl = MGA1064_MUL_CTL_16bits;
+		break;
+	case DRM_FORMAT_RGB888:
  		xmulctrl = MGA1064_MUL_CTL_24bits;
  		break;
-	case 32:
+	case DRM_FORMAT_XRGB8888:
  		xmulctrl = MGA1064_MUL_CTL_32_24bits;
  		break;
-	default:
-		/* BUG: We should have caught this problem already. */
-		drm_WARN_ON(dev, "invalid format depth\n");
-		return;
  	}
 
  	crtcext3 &= ~GENMASK(2, 0);
author maintainer
#4 lore raw

PATCH 2/6 drm/mgag200: Set scale from DRM format

In reply to Thomas Zimmermann

Replace the deprecated cpp value from struct drm_format_info with the format's 4CC code when setting the scale value in CRTCEXT3. While at it, remove the scale variable and add a mask constant.

---
 drivers/gpu/drm/mgag200/mgag200_mode.c | 30 +++++++++++++++-----------
 drivers/gpu/drm/mgag200/mgag200_reg.h  |  1 +
 2 files changed, 18 insertions(+), 13 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +17 -13
index 316413d814ae..5b526aebaeb8 100644
@@ -343,24 +343,31 @@ static void mgag200_set_offset(struct mga_device *mdev,
 
 void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_info *format)
 {
-	unsigned int bpp, bppshift, scale;
 	u8 xmulctrl = 0;
 	u8 crtcext3;
 
-	bpp = format->cpp[0] * 8;
+	RREG_ECRT(3, crtcext3);
 
-	bppshift = mgag200_get_bpp_shift(format);
-	switch (bpp) {
-	case 24:
-		scale = ((1 << bppshift) * 3) - 1;
+	switch (format->format) {
+	case DRM_FORMAT_C8:
+		crtcext3 &= ~MGAREG_CRTCEXT3_SCALE_MASK;
+		crtcext3 |= 0x0;
 		break;
-	default:
-		scale = (1 << bppshift) - 1;
+	case DRM_FORMAT_XRGB1555:
+	case DRM_FORMAT_RGB565:
+		crtcext3 &= ~MGAREG_CRTCEXT3_SCALE_MASK;
+		crtcext3 |= 0x01;
+		break;
+	case DRM_FORMAT_RGB888:
+		crtcext3 &= ~MGAREG_CRTCEXT3_SCALE_MASK;
+		crtcext3 |= 0x02;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		crtcext3 &= ~MGAREG_CRTCEXT3_SCALE_MASK;
+		crtcext3 |= 0x03;
 		break;
 	}
 
-	RREG_ECRT(3, crtcext3);
-
 	switch (format->format) {
 	case DRM_FORMAT_C8:
 		xmulctrl = MGA1064_MUL_CTL_8bits;
@@ -379,9 +386,6 @@ void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_in
 		break;
 	}
 
-	crtcext3 &= ~GENMASK(2, 0);
-	crtcext3 |= scale;
-
 	WREG_DAC(MGA1064_MUL_CTL, xmulctrl);
 
 	WREG_GFX(0, 0x00);
drivers/gpu/drm/mgag200/mgag200_reg.h +1 -0
index d4fef8f25871..088b6c16f7f6 100644
@@ -265,6 +265,7 @@
 #define MGAREG_CRTCEXT1_HRSTEN		BIT(3)
 
 #define MGAREG_CRTCEXT3_MGAMODE		BIT(7)
+#define MGAREG_CRTCEXT3_SCALE_MASK	GENMASK(2, 0)
 
 /* Cursor X and Y position */
 #define MGA_CURPOSXL 0x3c0c
Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 2/6
#5 lore raw

Re: [PATCH 2/6] drm/mgag200: Set scale from DRM format

Quoted 3 lines · Thomas Zimmermann

Replace the deprecated cpp value from struct drm_format_info with the format's 4CC code when setting the scale value in CRTCEXT3. While at it, remove the scale variable and add a mask constant.

Thanks, it looks good to me.

Quoted 75 lines
---
  drivers/gpu/drm/mgag200/mgag200_mode.c | 30 +++++++++++++++-----------
  drivers/gpu/drm/mgag200/mgag200_reg.h  |  1 +
  2 files changed, 18 insertions(+), 13 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +17 -13
index 316413d814ae..5b526aebaeb8 100644
@@ -343,24 +343,31 @@ static void mgag200_set_offset(struct mga_device *mdev,
 
  void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_info *format)
  {
-	unsigned int bpp, bppshift, scale;
  	u8 xmulctrl = 0;
  	u8 crtcext3;
 
-	bpp = format->cpp[0] * 8;
+	RREG_ECRT(3, crtcext3);
 
-	bppshift = mgag200_get_bpp_shift(format);
-	switch (bpp) {
-	case 24:
-		scale = ((1 << bppshift) * 3) - 1;
+	switch (format->format) {
+	case DRM_FORMAT_C8:
+		crtcext3 &= ~MGAREG_CRTCEXT3_SCALE_MASK;
+		crtcext3 |= 0x0;
  		break;
-	default:
-		scale = (1 << bppshift) - 1;
+	case DRM_FORMAT_XRGB1555:
+	case DRM_FORMAT_RGB565:
+		crtcext3 &= ~MGAREG_CRTCEXT3_SCALE_MASK;
+		crtcext3 |= 0x01;
+		break;
+	case DRM_FORMAT_RGB888:
+		crtcext3 &= ~MGAREG_CRTCEXT3_SCALE_MASK;
+		crtcext3 |= 0x02;
+		break;
+	case DRM_FORMAT_XRGB8888:
+		crtcext3 &= ~MGAREG_CRTCEXT3_SCALE_MASK;
+		crtcext3 |= 0x03;
  		break;
  	}
 
-	RREG_ECRT(3, crtcext3);
-
  	switch (format->format) {
  	case DRM_FORMAT_C8:
  		xmulctrl = MGA1064_MUL_CTL_8bits;
@@ -379,9 +386,6 @@ void mgag200_set_format_regs(struct mga_device *mdev, const struct drm_format_in
  		break;
  	}
 
-	crtcext3 &= ~GENMASK(2, 0);
-	crtcext3 |= scale;
-
  	WREG_DAC(MGA1064_MUL_CTL, xmulctrl);
 
  	WREG_GFX(0, 0x00);
drivers/gpu/drm/mgag200/mgag200_reg.h +1 -0
index d4fef8f25871..088b6c16f7f6 100644
@@ -265,6 +265,7 @@
  #define MGAREG_CRTCEXT1_HRSTEN		BIT(3)
 
  #define MGAREG_CRTCEXT3_MGAMODE		BIT(7)
+#define MGAREG_CRTCEXT3_SCALE_MASK	GENMASK(2, 0)
 
  /* Cursor X and Y position */
  #define MGA_CURPOSXL 0x3c0c
author maintainer
#6 lore raw

PATCH 3/6 drm/mgag200: Simplify offset calculation

In reply to Thomas Zimmermann

The offset value sets the distance in bytes between two consecutive scanlines. Reduce the calculation to the minimum.

According to the Matrox programming manual, Sec 4.6.5, the offset is the scanline pitch in bits divided by 128. The field pitches[0] in struct drm_framebuffer stores the scanline pitch in bytes, so we have to divide by 16 only. Reducing the existing bpp-shift look-up and offset calculations also returns exactly this for all formats.

---
 drivers/gpu/drm/mgag200/mgag200_mode.c | 28 +-------------------------
 1 file changed, 1 insertion(+), 27 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +1 -27
index 5b526aebaeb8..57c9f731a4bf 100644
@@ -298,37 +298,11 @@ void mgag200_set_mode_regs(struct mga_device *mdev, const struct drm_display_mod
 	WREG8(MGA_MISC_OUT, misc);
 }
 
-static u8 mgag200_get_bpp_shift(const struct drm_format_info *format)
-{
-	static const u8 bpp_shift[] = {0, 1, 0, 2};
-
-	return bpp_shift[format->cpp[0] - 1];
-}
-
-/*
- * Calculates the HW offset value from the framebuffer's pitch. The
- * offset is a multiple of the pixel size and depends on the display
- * format.
- */
-static u32 mgag200_calculate_offset(struct mga_device *mdev,
-				    const struct drm_framebuffer *fb)
-{
-	u32 offset = fb->pitches[0] / fb->format->cpp[0];
-	u8 bppshift = mgag200_get_bpp_shift(fb->format);
-
-	if (fb->format->cpp[0] * 8 == 24)
-		offset = (offset * 3) >> (4 - bppshift);
-	else
-		offset = offset >> (4 - bppshift);
-
-	return offset;
-}
-
 static void mgag200_set_offset(struct mga_device *mdev,
 			       const struct drm_framebuffer *fb)
 {
 	u8 crtc13, crtcext0;
-	u32 offset = mgag200_calculate_offset(mdev, fb);
+	u32 offset = fb->pitches[0] / 16;
 
 	RREG_ECRT(0, crtcext0);
 
Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 3/6
#7 lore raw

Re: [PATCH 3/6] drm/mgag200: Simplify offset calculation

Quoted 9 lines · Thomas Zimmermann

The offset value sets the distance in bytes between two consecutive scanlines. Reduce the calculation to the minimum.

According to the Matrox programming manual, Sec 4.6.5, the offset is the scanline pitch in bits divided by 128. The field pitches[0] in struct drm_framebuffer stores the scanline pitch in bytes, so we have to divide by 16 only. Reducing the existing bpp-shift look-up and offset calculations also returns exactly this for all formats.

I've sent a similar patch a few years ago with:
https://patchwork.freedesktop.org/patch/531878/?series=116381&rev=1

So that looks good to me.

Quoted 48 lines
---
  drivers/gpu/drm/mgag200/mgag200_mode.c | 28 +-------------------------
  1 file changed, 1 insertion(+), 27 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +1 -27
index 5b526aebaeb8..57c9f731a4bf 100644
@@ -298,37 +298,11 @@ void mgag200_set_mode_regs(struct mga_device *mdev, const struct drm_display_mod
  	WREG8(MGA_MISC_OUT, misc);
  }
 
-static u8 mgag200_get_bpp_shift(const struct drm_format_info *format)
-{
-	static const u8 bpp_shift[] = {0, 1, 0, 2};
-
-	return bpp_shift[format->cpp[0] - 1];
-}
-
-/*
- * Calculates the HW offset value from the framebuffer's pitch. The
- * offset is a multiple of the pixel size and depends on the display
- * format.
- */
-static u32 mgag200_calculate_offset(struct mga_device *mdev,
-				    const struct drm_framebuffer *fb)
-{
-	u32 offset = fb->pitches[0] / fb->format->cpp[0];
-	u8 bppshift = mgag200_get_bpp_shift(fb->format);
-
-	if (fb->format->cpp[0] * 8 == 24)
-		offset = (offset * 3) >> (4 - bppshift);
-	else
-		offset = offset >> (4 - bppshift);
-
-	return offset;
-}
-
  static void mgag200_set_offset(struct mga_device *mdev,
  			       const struct drm_framebuffer *fb)
  {
  	u8 crtc13, crtcext0;
-	u32 offset = mgag200_calculate_offset(mdev, fb);
+	u32 offset = fb->pitches[0] / 16;
 
  	RREG_ECRT(0, crtcext0);
 
author maintainer
#8 lore raw

Re: [PATCH 3/6] drm/mgag200: Simplify offset calculation

Hi Jocelyn

Am 16.04.26 um 09:34 schrieb Jocelyn Falempe:

Quoted 12 lines · Thomas Zimmermann
Quoted 9 lines

The offset value sets the distance in bytes between two consecutive scanlines. Reduce the calculation to the minimum.

According to the Matrox programming manual, Sec 4.6.5, the offset is the scanline pitch in bits divided by 128. The field pitches[0] in struct drm_framebuffer stores the scanline pitch in bytes, so we have to divide by 16 only. Reducing the existing bpp-shift look-up and offset calculations also returns exactly this for all formats.

I've sent a similar patch a few years ago with:
https://patchwork.freedesktop.org/patch/531878/?series=116381&rev=1

Ah, that was part of the 24-bit change so it didn't make it in. Let me give you at least credit for the work.

Best regards
Thomas

Quoted 52 lines

So that looks good to me.

Quoted 46 lines

---
  drivers/gpu/drm/mgag200/mgag200_mode.c | 28 +-------------------------

  1 file changed, 1 insertion(+), 27 deletions(-)
drivers/gpu/drm/mgag200/mgag200_mode.c +1 -26
index 5b526aebaeb8..57c9f731a4bf 100644
@@ -298,37 +298,11 @@ void mgag200_set_mode_regs(struct mga_device 
 *mdev, const struct drm_display_mod
       WREG8(MGA_MISC_OUT, misc);
   }
   -static u8 mgag200_get_bpp_shift(const struct drm_format_info *format)
-{
-    static const u8 bpp_shift[] = {0, 1, 0, 2};
-
-    return bpp_shift[format->cpp[0] - 1];
-}
-
-/*
- * Calculates the HW offset value from the framebuffer's pitch. The
- * offset is a multiple of the pixel size and depends on the display
- * format.
- */
-static u32 mgag200_calculate_offset(struct mga_device *mdev,
-                    const struct drm_framebuffer *fb)
-{
-    u32 offset = fb->pitches[0] / fb->format->cpp[0];
-    u8 bppshift = mgag200_get_bpp_shift(fb->format);
-
-    if (fb->format->cpp[0] * 8 == 24)
-        offset = (offset * 3) >> (4 - bppshift);
-    else
-        offset = offset >> (4 - bppshift);
-
-    return offset;
-}
-
   static void mgag200_set_offset(struct mga_device *mdev,
                      const struct drm_framebuffer *fb)
   {
       u8 crtc13, crtcext0;
-    u32 offset = mgag200_calculate_offset(mdev, fb);
+    u32 offset = fb->pitches[0] / 16;
         RREG_ECRT(0, crtcext0);
Signature · 6 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Jochen Jaser, Andrew McDonald, Werner Knoblich, (HRB 36809, AG Nürnberg)
author maintainer
#9 lore raw

PATCH 4/6 drm/mgag200: g200se: Set hiprilvl from DRM format

In reply to Thomas Zimmermann

Replace the deprecated cpp field from struct drm_format_info with the format's 4CC code when setting the hiprilvl field in CRTCEXT6.

Using a bpp of 32 for RGB888 is a bit dubious, but we keep it for now to avoid changing behavior. Otherwise, bpp could also be retrieved by calling drm_format_info_bpp().

---
 drivers/gpu/drm/mgag200/mgag200_g200se.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/mgag200/mgag200_g200se.c +9 -3
index a0ac19ee0353..746ce11b75fb 100644
@@ -76,12 +76,18 @@ static void mgag200_g200se_set_hiprilvl(struct mga_device *mdev,
 		unsigned int bpp;
 		unsigned long mb;
 
-		if (format->cpp[0] * 8 > 16)
+		switch (format->format) {
+		case DRM_FORMAT_XRGB8888:
+		case DRM_FORMAT_RGB888:
 			bpp = 32;
-		else if (format->cpp[0] * 8 > 8)
+			break;
+		case DRM_FORMAT_RGB565:
 			bpp = 16;
-		else
+			break;
+		case DRM_FORMAT_C8:
 			bpp = 8;
+			break;
+		}
 
 		mb = (mode->clock * bpp) / 1000;
 		if (mb > 3100)
Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 4/6
#10 lore raw

Re: [PATCH 4/6] drm/mgag200: g200se: Set hiprilvl from DRM format

Quoted 6 lines · Thomas Zimmermann

Replace the deprecated cpp field from struct drm_format_info with the format's 4CC code when setting the hiprilvl field in CRTCEXT6.

Using a bpp of 32 for RGB888 is a bit dubious, but we keep it for now to avoid changing behavior. Otherwise, bpp could also be retrieved by calling drm_format_info_bpp().

Thanks, it looks good to me.

Quoted 32 lines
---
  drivers/gpu/drm/mgag200/mgag200_g200se.c | 12 +++++++++---
  1 file changed, 9 insertions(+), 3 deletions(-)
drivers/gpu/drm/mgag200/mgag200_g200se.c +9 -3
index a0ac19ee0353..746ce11b75fb 100644
@@ -76,12 +76,18 @@ static void mgag200_g200se_set_hiprilvl(struct mga_device *mdev,
  		unsigned int bpp;
  		unsigned long mb;
 
-		if (format->cpp[0] * 8 > 16)
+		switch (format->format) {
+		case DRM_FORMAT_XRGB8888:
+		case DRM_FORMAT_RGB888:
  			bpp = 32;
-		else if (format->cpp[0] * 8 > 8)
+			break;
+		case DRM_FORMAT_RGB565:
  			bpp = 16;
-		else
+			break;
+		case DRM_FORMAT_C8:
  			bpp = 8;
+			break;
+		}
 
  		mb = (mode->clock * bpp) / 1000;
  		if (mb > 3100)
author maintainer
#11 lore raw

PATCH 5/6 drm/mgag200: Enable DRM_FORMAT_C8 on the primary plane

In reply to Thomas Zimmermann

The driver already contains all format setting for DRM_FORMAT_C8. Set the gamma-correction helpers and add the format to the array of plane formats.

---
 drivers/gpu/drm/mgag200/mgag200_mode.c | 7 +++++++
 1 file changed, 7 insertions(+)
drivers/gpu/drm/mgag200/mgag200_mode.c +7 -0
index 57c9f731a4bf..7fe1d492083e 100644
@@ -56,6 +56,9 @@ void mgag200_crtc_fill_gamma(struct mga_device *mdev,
 	struct drm_crtc *crtc = &mdev->crtc;
 
 	switch (format->format) {
+	case DRM_FORMAT_C8:
+		drm_crtc_fill_palette_8(crtc, mgag200_set_gamma_lut);
+		break;
 	case DRM_FORMAT_RGB565:
 		drm_crtc_fill_gamma_565(crtc, mgag200_set_gamma_lut);
 		break;
@@ -77,6 +80,9 @@ void mgag200_crtc_load_gamma(struct mga_device *mdev,
 	struct drm_crtc *crtc = &mdev->crtc;
 
 	switch (format->format) {
+	case DRM_FORMAT_C8:
+		drm_crtc_load_palette_8(crtc, lut, mgag200_set_gamma_lut);
+		break;
 	case DRM_FORMAT_RGB565:
 		drm_crtc_load_gamma_565_from_888(crtc, lut, mgag200_set_gamma_lut);
 		break;
@@ -438,6 +444,7 @@ const uint32_t mgag200_primary_plane_formats[] = {
 	DRM_FORMAT_XRGB8888,
 	DRM_FORMAT_RGB565,
 	DRM_FORMAT_RGB888,
+	DRM_FORMAT_C8,
 };
 
 const size_t mgag200_primary_plane_formats_size = ARRAY_SIZE(mgag200_primary_plane_formats);
Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 5/6
#12 lore raw

Re: [PATCH 5/6] drm/mgag200: Enable DRM_FORMAT_C8 on the primary plane

Quoted 3 lines · Thomas Zimmermann

The driver already contains all format setting for DRM_FORMAT_C8. Set the gamma-correction helpers and add the format to the array of plane formats.

Thanks, it looks good to me.

Quoted 38 lines
---
  drivers/gpu/drm/mgag200/mgag200_mode.c | 7 +++++++
  1 file changed, 7 insertions(+)
drivers/gpu/drm/mgag200/mgag200_mode.c +7 -0
index 57c9f731a4bf..7fe1d492083e 100644
@@ -56,6 +56,9 @@ void mgag200_crtc_fill_gamma(struct mga_device *mdev,
  	struct drm_crtc *crtc = &mdev->crtc;
 
  	switch (format->format) {
+	case DRM_FORMAT_C8:
+		drm_crtc_fill_palette_8(crtc, mgag200_set_gamma_lut);
+		break;
  	case DRM_FORMAT_RGB565:
  		drm_crtc_fill_gamma_565(crtc, mgag200_set_gamma_lut);
  		break;
@@ -77,6 +80,9 @@ void mgag200_crtc_load_gamma(struct mga_device *mdev,
  	struct drm_crtc *crtc = &mdev->crtc;
 
  	switch (format->format) {
+	case DRM_FORMAT_C8:
+		drm_crtc_load_palette_8(crtc, lut, mgag200_set_gamma_lut);
+		break;
  	case DRM_FORMAT_RGB565:
  		drm_crtc_load_gamma_565_from_888(crtc, lut, mgag200_set_gamma_lut);
  		break;
@@ -438,6 +444,7 @@ const uint32_t mgag200_primary_plane_formats[] = {
  	DRM_FORMAT_XRGB8888,
  	DRM_FORMAT_RGB565,
  	DRM_FORMAT_RGB888,
+	DRM_FORMAT_C8,
  };
 
  const size_t mgag200_primary_plane_formats_size = ARRAY_SIZE(mgag200_primary_plane_formats);
author maintainer
#13 lore raw

PATCH 6/6 drm/mgag200: Enable DRM_FORMAT_XRGB1555 on the primary plane

In reply to Thomas Zimmermann

The driver already sets the format for the depth value in the XMULCTRL register. Add the format to the other switch statements, set the helpers for gamma correction and export the XRGB1555 in the primary plane's format array.

---
 drivers/gpu/drm/mgag200/mgag200_g200se.c | 1 +
 drivers/gpu/drm/mgag200/mgag200_mode.c   | 8 ++++++++
 2 files changed, 9 insertions(+)
drivers/gpu/drm/mgag200/mgag200_g200se.c +1 -0
index 746ce11b75fb..5c2185d6b707 100644
@@ -82,6 +82,7 @@ static void mgag200_g200se_set_hiprilvl(struct mga_device *mdev,
 			bpp = 32;
 			break;
 		case DRM_FORMAT_RGB565:
+		case DRM_FORMAT_XRGB1555:
 			bpp = 16;
 			break;
 		case DRM_FORMAT_C8:
drivers/gpu/drm/mgag200/mgag200_mode.c +8 -0
index 7fe1d492083e..bd346b828773 100644
@@ -59,6 +59,9 @@ void mgag200_crtc_fill_gamma(struct mga_device *mdev,
 	case DRM_FORMAT_C8:
 		drm_crtc_fill_palette_8(crtc, mgag200_set_gamma_lut);
 		break;
+	case DRM_FORMAT_XRGB1555:
+		drm_crtc_fill_gamma_555(crtc, mgag200_set_gamma_lut);
+		break;
 	case DRM_FORMAT_RGB565:
 		drm_crtc_fill_gamma_565(crtc, mgag200_set_gamma_lut);
 		break;
@@ -83,6 +86,9 @@ void mgag200_crtc_load_gamma(struct mga_device *mdev,
 	case DRM_FORMAT_C8:
 		drm_crtc_load_palette_8(crtc, lut, mgag200_set_gamma_lut);
 		break;
+	case DRM_FORMAT_XRGB1555:
+		drm_crtc_load_gamma_555_from_888(crtc, lut, mgag200_set_gamma_lut);
+		break;
 	case DRM_FORMAT_RGB565:
 		drm_crtc_load_gamma_565_from_888(crtc, lut, mgag200_set_gamma_lut);
 		break;
@@ -180,6 +186,7 @@ static void mgag200_set_datasiz(struct mga_device *mdev, u32 format)
 
 	/* Big-endian byte-swapping */
 	switch (format) {
+	case DRM_FORMAT_XRGB1555:
 	case DRM_FORMAT_RGB565:
 		opmode |= 0x10100;
 		break;
@@ -443,6 +450,7 @@ static void mgag200_handle_damage(struct mga_device *mdev, const struct iosys_ma
 const uint32_t mgag200_primary_plane_formats[] = {
 	DRM_FORMAT_XRGB8888,
 	DRM_FORMAT_RGB565,
+	DRM_FORMAT_XRGB1555,
 	DRM_FORMAT_RGB888,
 	DRM_FORMAT_C8,
 };
Signature · 1 line
2.53.0
reviewer Reviewed-by on v1 6/6
#14 lore raw

Re: [PATCH 6/6] drm/mgag200: Enable DRM_FORMAT_XRGB1555 on the primary plane

Quoted 4 lines · Thomas Zimmermann

The driver already sets the format for the depth value in the XMULCTRL register. Add the format to the other switch statements, set the helpers for gamma correction and export the XRGB1555 in the primary plane's format array.

Thanks, it looks good to me.

Quoted 59 lines
---
  drivers/gpu/drm/mgag200/mgag200_g200se.c | 1 +
  drivers/gpu/drm/mgag200/mgag200_mode.c   | 8 ++++++++
  2 files changed, 9 insertions(+)
drivers/gpu/drm/mgag200/mgag200_g200se.c +1 -0
index 746ce11b75fb..5c2185d6b707 100644
@@ -82,6 +82,7 @@ static void mgag200_g200se_set_hiprilvl(struct mga_device *mdev,
  			bpp = 32;
  			break;
  		case DRM_FORMAT_RGB565:
+		case DRM_FORMAT_XRGB1555:
  			bpp = 16;
  			break;
  		case DRM_FORMAT_C8:
drivers/gpu/drm/mgag200/mgag200_mode.c +8 -0
index 7fe1d492083e..bd346b828773 100644
@@ -59,6 +59,9 @@ void mgag200_crtc_fill_gamma(struct mga_device *mdev,
  	case DRM_FORMAT_C8:
  		drm_crtc_fill_palette_8(crtc, mgag200_set_gamma_lut);
  		break;
+	case DRM_FORMAT_XRGB1555:
+		drm_crtc_fill_gamma_555(crtc, mgag200_set_gamma_lut);
+		break;
  	case DRM_FORMAT_RGB565:
  		drm_crtc_fill_gamma_565(crtc, mgag200_set_gamma_lut);
  		break;
@@ -83,6 +86,9 @@ void mgag200_crtc_load_gamma(struct mga_device *mdev,
  	case DRM_FORMAT_C8:
  		drm_crtc_load_palette_8(crtc, lut, mgag200_set_gamma_lut);
  		break;
+	case DRM_FORMAT_XRGB1555:
+		drm_crtc_load_gamma_555_from_888(crtc, lut, mgag200_set_gamma_lut);
+		break;
  	case DRM_FORMAT_RGB565:
  		drm_crtc_load_gamma_565_from_888(crtc, lut, mgag200_set_gamma_lut);
  		break;
@@ -180,6 +186,7 @@ static void mgag200_set_datasiz(struct mga_device *mdev, u32 format)
 
  	/* Big-endian byte-swapping */
  	switch (format) {
+	case DRM_FORMAT_XRGB1555:
  	case DRM_FORMAT_RGB565:
  		opmode |= 0x10100;
  		break;
@@ -443,6 +450,7 @@ static void mgag200_handle_damage(struct mga_device *mdev, const struct iosys_ma
  const uint32_t mgag200_primary_plane_formats[] = {
  	DRM_FORMAT_XRGB8888,
  	DRM_FORMAT_RGB565,
+	DRM_FORMAT_XRGB1555,
  	DRM_FORMAT_RGB888,
  	DRM_FORMAT_C8,
  };