]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/mgag200: Simplify offset calculation
authorThomas Zimmermann <tzimmermann@suse.de>
Wed, 15 Apr 2026 15:23:37 +0000 (17:23 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Mon, 20 Apr 2026 07:15:57 +0000 (09:15 +0200)
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.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Co-developed-by: Jocelyn Falempe <jfalempe@redhat.com>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://patch.msgid.link/20260415152625.101710-4-tzimmermann@suse.de
drivers/gpu/drm/mgag200/mgag200_mode.c

index 5b526aebaeb84866acd86890aa1ca25d0db104e6..57c9f731a4bf137275df9186d838b7669577575d 100644 (file)
@@ -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);