Linux 4.9.243
[linux/fpc-iii.git] / drivers / gpu / drm / mgag200 / mgag200_drv.c
blob1443b3a34775cbcaca50532482cfa32fd3052671
1 /*
2 * Copyright 2012 Red Hat
4 * This file is subject to the terms and conditions of the GNU General
5 * Public License version 2. See the file COPYING in the main
6 * directory of this archive for more details.
8 * Authors: Matthew Garrett
9 * Dave Airlie
11 #include <linux/module.h>
12 #include <linux/console.h>
13 #include <drm/drmP.h>
15 #include "mgag200_drv.h"
17 #include <drm/drm_pciids.h>
20 * This is the generic driver code. This binds the driver to the drm core,
21 * which then performs further device association and calls our graphics init
22 * functions
24 int mgag200_modeset = -1;
26 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
27 module_param_named(modeset, mgag200_modeset, int, 0400);
29 static struct drm_driver driver;
31 static const struct pci_device_id pciidlist[] = {
32 { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_A },
33 { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
34 { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
35 { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
36 { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
37 { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
38 { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
39 {0,}
42 MODULE_DEVICE_TABLE(pci, pciidlist);
44 static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev)
46 struct apertures_struct *ap;
47 bool primary = false;
49 ap = alloc_apertures(1);
50 if (!ap)
51 return;
53 ap->ranges[0].base = pci_resource_start(pdev, 0);
54 ap->ranges[0].size = pci_resource_len(pdev, 0);
56 #ifdef CONFIG_X86
57 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
58 #endif
59 drm_fb_helper_remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
60 kfree(ap);
64 static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
66 mgag200_kick_out_firmware_fb(pdev);
68 return drm_get_pci_dev(pdev, ent, &driver);
71 static void mga_pci_remove(struct pci_dev *pdev)
73 struct drm_device *dev = pci_get_drvdata(pdev);
75 drm_put_dev(dev);
78 static const struct file_operations mgag200_driver_fops = {
79 .owner = THIS_MODULE,
80 .open = drm_open,
81 .release = drm_release,
82 .unlocked_ioctl = drm_ioctl,
83 .mmap = mgag200_mmap,
84 .poll = drm_poll,
85 #ifdef CONFIG_COMPAT
86 .compat_ioctl = drm_compat_ioctl,
87 #endif
88 .read = drm_read,
91 static struct drm_driver driver = {
92 .driver_features = DRIVER_GEM | DRIVER_MODESET,
93 .load = mgag200_driver_load,
94 .unload = mgag200_driver_unload,
95 .set_busid = drm_pci_set_busid,
96 .fops = &mgag200_driver_fops,
97 .name = DRIVER_NAME,
98 .desc = DRIVER_DESC,
99 .date = DRIVER_DATE,
100 .major = DRIVER_MAJOR,
101 .minor = DRIVER_MINOR,
102 .patchlevel = DRIVER_PATCHLEVEL,
104 .gem_free_object_unlocked = mgag200_gem_free_object,
105 .dumb_create = mgag200_dumb_create,
106 .dumb_map_offset = mgag200_dumb_mmap_offset,
107 .dumb_destroy = drm_gem_dumb_destroy,
110 static struct pci_driver mgag200_pci_driver = {
111 .name = DRIVER_NAME,
112 .id_table = pciidlist,
113 .probe = mga_pci_probe,
114 .remove = mga_pci_remove,
117 static int __init mgag200_init(void)
119 if (vgacon_text_force() && mgag200_modeset == -1)
120 return -EINVAL;
122 if (mgag200_modeset == 0)
123 return -EINVAL;
124 return drm_pci_init(&driver, &mgag200_pci_driver);
127 static void __exit mgag200_exit(void)
129 drm_pci_exit(&driver, &mgag200_pci_driver);
132 module_init(mgag200_init);
133 module_exit(mgag200_exit);
135 MODULE_AUTHOR(DRIVER_AUTHOR);
136 MODULE_DESCRIPTION(DRIVER_DESC);
137 MODULE_LICENSE("GPL");