1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2012 Red Hat
5 * Authors: Matthew Garrett
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
26 int mgag200_modeset = -1;
27 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
28 module_param_named(modeset, mgag200_modeset, int, 0400);
30 static struct drm_driver driver;
32 static const struct pci_device_id pciidlist[] = {
33 { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0,
34 G200_SE_A | MGAG200_FLAG_HW_BUG_NO_STARTADD},
35 { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
36 { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
37 { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
38 { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
39 { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
40 { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
41 { PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
45 MODULE_DEVICE_TABLE(pci, pciidlist);
48 static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
50 struct drm_device *dev;
53 drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "mgag200drmfb");
55 ret = pci_enable_device(pdev);
59 dev = drm_dev_alloc(&driver, &pdev->dev);
62 goto err_pci_disable_device;
66 pci_set_drvdata(pdev, dev);
68 ret = mgag200_driver_load(dev, ent->driver_data);
72 ret = drm_dev_register(dev, ent->driver_data);
74 goto err_mgag200_driver_unload;
76 drm_fbdev_generic_setup(dev, 0);
80 err_mgag200_driver_unload:
81 mgag200_driver_unload(dev);
84 err_pci_disable_device:
85 pci_disable_device(pdev);
89 static void mga_pci_remove(struct pci_dev *pdev)
91 struct drm_device *dev = pci_get_drvdata(pdev);
93 drm_dev_unregister(dev);
94 mgag200_driver_unload(dev);
98 DEFINE_DRM_GEM_FOPS(mgag200_driver_fops);
100 static struct drm_driver driver = {
101 .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET,
102 .fops = &mgag200_driver_fops,
106 .major = DRIVER_MAJOR,
107 .minor = DRIVER_MINOR,
108 .patchlevel = DRIVER_PATCHLEVEL,
109 DRM_GEM_SHMEM_DRIVER_OPS,
112 static struct pci_driver mgag200_pci_driver = {
114 .id_table = pciidlist,
115 .probe = mga_pci_probe,
116 .remove = mga_pci_remove,
119 static int __init mgag200_init(void)
121 if (vgacon_text_force() && mgag200_modeset == -1)
124 if (mgag200_modeset == 0)
127 return pci_register_driver(&mgag200_pci_driver);
130 static void __exit mgag200_exit(void)
132 pci_unregister_driver(&mgag200_pci_driver);
135 module_init(mgag200_init);
136 module_exit(mgag200_exit);
138 MODULE_AUTHOR(DRIVER_AUTHOR);
139 MODULE_DESCRIPTION(DRIVER_DESC);
140 MODULE_LICENSE("GPL");