treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / gpu / drm / mgag200 / mgag200_drv.c
blob7a5bad2f57d70bbe838a46c8e29f800e4466f313
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * Copyright 2012 Red Hat
5 * Authors: Matthew Garrett
6 * Dave Airlie
7 */
9 #include <linux/console.h>
10 #include <linux/module.h>
11 #include <linux/pci.h>
13 #include <drm/drm_drv.h>
14 #include <drm/drm_file.h>
15 #include <drm/drm_ioctl.h>
16 #include <drm/drm_pciids.h>
18 #include "mgag200_drv.h"
21 * This is the generic driver code. This binds the driver to the drm core,
22 * which then performs further device association and calls our graphics init
23 * functions
25 int mgag200_modeset = -1;
27 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
28 module_param_named(modeset, mgag200_modeset, int, 0400);
30 int mgag200_hw_bug_no_startadd = -1;
31 MODULE_PARM_DESC(modeset, "HW does not interpret scanout-buffer start address correctly");
32 module_param_named(hw_bug_no_startadd, mgag200_hw_bug_no_startadd, int, 0400);
34 static struct drm_driver driver;
36 static const struct pci_device_id pciidlist[] = {
37 { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
38 G200_SE_A | MGAG200_FLAG_HW_BUG_NO_STARTADD},
39 { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
40 { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
41 { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
42 { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
43 { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
44 { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
45 { PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
46 {0,}
49 MODULE_DEVICE_TABLE(pci, pciidlist);
52 static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
54 struct drm_device *dev;
55 int ret;
57 drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "mgag200drmfb");
59 ret = pci_enable_device(pdev);
60 if (ret)
61 return ret;
63 dev = drm_dev_alloc(&driver, &pdev->dev);
64 if (IS_ERR(dev)) {
65 ret = PTR_ERR(dev);
66 goto err_pci_disable_device;
69 dev->pdev = pdev;
70 pci_set_drvdata(pdev, dev);
72 ret = mgag200_driver_load(dev, ent->driver_data);
73 if (ret)
74 goto err_drm_dev_put;
76 ret = drm_dev_register(dev, ent->driver_data);
77 if (ret)
78 goto err_mgag200_driver_unload;
80 return 0;
82 err_mgag200_driver_unload:
83 mgag200_driver_unload(dev);
84 err_drm_dev_put:
85 drm_dev_put(dev);
86 err_pci_disable_device:
87 pci_disable_device(pdev);
88 return ret;
91 static void mga_pci_remove(struct pci_dev *pdev)
93 struct drm_device *dev = pci_get_drvdata(pdev);
95 drm_dev_unregister(dev);
96 mgag200_driver_unload(dev);
97 drm_dev_put(dev);
100 DEFINE_DRM_GEM_FOPS(mgag200_driver_fops);
102 static bool mgag200_pin_bo_at_0(const struct mga_device *mdev)
104 if (mgag200_hw_bug_no_startadd > 0) {
105 DRM_WARN_ONCE("Option hw_bug_no_startradd is enabled. Please "
106 "report the output of 'lspci -vvnn' to "
107 "<dri-devel@lists.freedesktop.org> if this "
108 "option is required to make mgag200 work "
109 "correctly on your system.\n");
110 return true;
111 } else if (!mgag200_hw_bug_no_startadd) {
112 return false;
114 return mdev->flags & MGAG200_FLAG_HW_BUG_NO_STARTADD;
117 int mgag200_driver_dumb_create(struct drm_file *file,
118 struct drm_device *dev,
119 struct drm_mode_create_dumb *args)
121 struct mga_device *mdev = dev->dev_private;
122 unsigned long pg_align;
124 if (WARN_ONCE(!dev->vram_mm, "VRAM MM not initialized"))
125 return -EINVAL;
127 pg_align = 0ul;
130 * Aligning scanout buffers to the size of the video ram forces
131 * placement at offset 0. Works around a bug where HW does not
132 * respect 'startadd' field.
134 if (mgag200_pin_bo_at_0(mdev))
135 pg_align = PFN_UP(mdev->mc.vram_size);
137 return drm_gem_vram_fill_create_dumb(file, dev, pg_align, 0, args);
140 static struct drm_driver driver = {
141 .driver_features = DRIVER_GEM | DRIVER_MODESET,
142 .fops = &mgag200_driver_fops,
143 .name = DRIVER_NAME,
144 .desc = DRIVER_DESC,
145 .date = DRIVER_DATE,
146 .major = DRIVER_MAJOR,
147 .minor = DRIVER_MINOR,
148 .patchlevel = DRIVER_PATCHLEVEL,
149 .debugfs_init = drm_vram_mm_debugfs_init,
150 .dumb_create = mgag200_driver_dumb_create,
151 .dumb_map_offset = drm_gem_vram_driver_dumb_mmap_offset,
152 .gem_prime_mmap = drm_gem_prime_mmap,
155 static struct pci_driver mgag200_pci_driver = {
156 .name = DRIVER_NAME,
157 .id_table = pciidlist,
158 .probe = mga_pci_probe,
159 .remove = mga_pci_remove,
162 static int __init mgag200_init(void)
164 if (vgacon_text_force() && mgag200_modeset == -1)
165 return -EINVAL;
167 if (mgag200_modeset == 0)
168 return -EINVAL;
170 return pci_register_driver(&mgag200_pci_driver);
173 static void __exit mgag200_exit(void)
175 pci_unregister_driver(&mgag200_pci_driver);
178 module_init(mgag200_init);
179 module_exit(mgag200_exit);
181 MODULE_AUTHOR(DRIVER_AUTHOR);
182 MODULE_DESCRIPTION(DRIVER_DESC);
183 MODULE_LICENSE("GPL");