drm/mgag200: Move register initialization into helper function
authorThomas Zimmermann <tzimmermann@suse.de>
Thu, 30 Jul 2020 10:28:38 +0000 (12:28 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Mon, 3 Aug 2020 07:42:11 +0000 (09:42 +0200)
The mgag200 driver maps registers into the address space. Move the
code into a separate helper function. No functional changes.

One small difference is in the handling of SDRAM/SGRAM. MGA devices
can come with either SDRAM or SGRAM. So far, the driver checked for
SDRAM, which is the common case. The patch moves this code into a
separate helper and checks for SGRAM, which is the special case. The
test itself is the same as before.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20200730102844.10995-3-tzimmermann@suse.de
drivers/gpu/drm/mgag200/mgag200_drv.c
drivers/gpu/drm/mgag200/mgag200_reg.h

index 7189c7745baf877e47aac5bff859f877686836d0..e50c682c4702a7e65a36714748703420bdcfe522 100644 (file)
@@ -44,18 +44,26 @@ static struct drm_driver mgag200_driver = {
  * DRM device
  */
 
-static int mgag200_device_init(struct mga_device *mdev, unsigned long flags)
+static bool mgag200_has_sgram(struct mga_device *mdev)
 {
        struct drm_device *dev = &mdev->base;
-       int ret, option;
+       u32 option;
+       int ret;
 
-       mdev->flags = mgag200_flags_from_driver_data(flags);
-       mdev->type = mgag200_type_from_driver_data(flags);
+       ret = pci_read_config_dword(dev->pdev, PCI_MGA_OPTION, &option);
+       if (drm_WARN(dev, ret, "failed to read PCI config dword: %d\n", ret))
+               return false;
+
+       return !!(option & PCI_MGA_OPTION_HARDPWMSK);
+}
 
-       pci_read_config_dword(dev->pdev, PCI_MGA_OPTION, &option);
-       mdev->has_sdram = !(option & (1 << 14));
+static int mgag200_regs_init(struct mga_device *mdev)
+{
+       struct drm_device *dev = &mdev->base;
+
+       mdev->has_sdram = !mgag200_has_sgram(mdev);
 
-       /* BAR 0 is the framebuffer, BAR 1 contains registers */
+       /* BAR 1 contains registers */
        mdev->rmmio_base = pci_resource_start(dev->pdev, 1);
        mdev->rmmio_size = pci_resource_len(dev->pdev, 1);
 
@@ -69,6 +77,21 @@ static int mgag200_device_init(struct mga_device *mdev, unsigned long flags)
        if (mdev->rmmio == NULL)
                return -ENOMEM;
 
+       return 0;
+}
+
+static int mgag200_device_init(struct mga_device *mdev, unsigned long flags)
+{
+       struct drm_device *dev = &mdev->base;
+       int ret;
+
+       mdev->flags = mgag200_flags_from_driver_data(flags);
+       mdev->type = mgag200_type_from_driver_data(flags);
+
+       ret = mgag200_regs_init(mdev);
+       if (ret)
+               return ret;
+
        /* stash G200 SE model number for later use */
        if (IS_G200_SE(mdev)) {
                mdev->unique_rev_id = RREG32(0x1e24);
index c3b7bcad52ed180eb73768db11ca03365d87667c..a44c08bf40741d40f2cf994aa068d959a992dc2a 100644 (file)
 #define PCI_MGA_OPTION2                0x50
 #define PCI_MGA_OPTION3                0x54
 
+#define PCI_MGA_OPTION_HARDPWMSK       BIT(14)
+
 #define RAMDAC_OFFSET          0x3c00
 
 /* TVP3026 direct registers */