1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright 2012 Red Hat
4  *
5  * Authors: Matthew Garrett
6  *          Dave Airlie
7  */
8 
9 #include <linux/module.h>
10 #include <linux/console.h>
11 
12 #include <drm/drm_drv.h>
13 #include <drm/drm_file.h>
14 #include <drm/drm_ioctl.h>
15 #include <drm/drm_pci.h>
16 #include <drm/drm_pciids.h>
17 
18 #include "mgag200_drv.h"
19 
20 /*
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
24  */
25 int mgag200_modeset = -1;
26 
27 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
28 module_param_named(modeset, mgag200_modeset, int, 0400);
29 
30 static struct drm_driver driver;
31 
32 static const struct pci_device_id pciidlist[] = {
33 	{ PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_A },
34 	{ PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
35 	{ PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
36 	{ PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
37 	{ PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
38 	{ PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
39 	{ PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
40 	{ PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
41 	{0,}
42 };
43 
44 MODULE_DEVICE_TABLE(pci, pciidlist);
45 
46 
47 static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
48 {
49 	drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "mgag200drmfb");
50 
51 	return drm_get_pci_dev(pdev, ent, &driver);
52 }
53 
54 static void mga_pci_remove(struct pci_dev *pdev)
55 {
56 	struct drm_device *dev = pci_get_drvdata(pdev);
57 
58 	drm_put_dev(dev);
59 }
60 
61 static const struct file_operations mgag200_driver_fops = {
62 	.owner = THIS_MODULE,
63 	DRM_VRAM_MM_FILE_OPERATIONS
64 };
65 
66 static struct drm_driver driver = {
67 	.driver_features = DRIVER_GEM | DRIVER_MODESET,
68 	.load = mgag200_driver_load,
69 	.unload = mgag200_driver_unload,
70 	.fops = &mgag200_driver_fops,
71 	.name = DRIVER_NAME,
72 	.desc = DRIVER_DESC,
73 	.date = DRIVER_DATE,
74 	.major = DRIVER_MAJOR,
75 	.minor = DRIVER_MINOR,
76 	.patchlevel = DRIVER_PATCHLEVEL,
77 	DRM_GEM_VRAM_DRIVER
78 };
79 
80 static struct pci_driver mgag200_pci_driver = {
81 	.name = DRIVER_NAME,
82 	.id_table = pciidlist,
83 	.probe = mga_pci_probe,
84 	.remove = mga_pci_remove,
85 };
86 
87 static int __init mgag200_init(void)
88 {
89 	if (vgacon_text_force() && mgag200_modeset == -1)
90 		return -EINVAL;
91 
92 	if (mgag200_modeset == 0)
93 		return -EINVAL;
94 
95 	return pci_register_driver(&mgag200_pci_driver);
96 }
97 
98 static void __exit mgag200_exit(void)
99 {
100 	pci_unregister_driver(&mgag200_pci_driver);
101 }
102 
103 module_init(mgag200_init);
104 module_exit(mgag200_exit);
105 
106 MODULE_AUTHOR(DRIVER_AUTHOR);
107 MODULE_DESCRIPTION(DRIVER_DESC);
108 MODULE_LICENSE("GPL");
109