1f2a034d5a9b3c18cfc04af244f559375adfb2d1
[sfrench/cifs-2.6.git] / drivers / gpu / drm / mgag200 / mgag200_drv.c
1 /*
2  * Copyright 2012 Red Hat
3  *
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.
7  *
8  * Authors: Matthew Garrett
9  *          Dave Airlie
10  */
11 #include <linux/module.h>
12 #include <linux/console.h>
13 #include <drm/drmP.h>
14
15 #include "mgag200_drv.h"
16
17 #include <drm/drm_pciids.h>
18
19 /*
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
23  */
24 int mgag200_modeset = -1;
25
26 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
27 module_param_named(modeset, mgag200_modeset, int, 0400);
28
29 static struct drm_driver driver;
30
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         { PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
40         {0,}
41 };
42
43 MODULE_DEVICE_TABLE(pci, pciidlist);
44
45
46 static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47 {
48         drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "mgag200drmfb");
49
50         return drm_get_pci_dev(pdev, ent, &driver);
51 }
52
53 static void mga_pci_remove(struct pci_dev *pdev)
54 {
55         struct drm_device *dev = pci_get_drvdata(pdev);
56
57         drm_put_dev(dev);
58 }
59
60 static const struct file_operations mgag200_driver_fops = {
61         .owner = THIS_MODULE,
62         .open = drm_open,
63         .release = drm_release,
64         .unlocked_ioctl = drm_ioctl,
65         .mmap = mgag200_mmap,
66         .poll = drm_poll,
67         .compat_ioctl = drm_compat_ioctl,
68         .read = drm_read,
69 };
70
71 static struct drm_driver driver = {
72         .driver_features = DRIVER_GEM | DRIVER_MODESET,
73         .load = mgag200_driver_load,
74         .unload = mgag200_driver_unload,
75         .fops = &mgag200_driver_fops,
76         .name = DRIVER_NAME,
77         .desc = DRIVER_DESC,
78         .date = DRIVER_DATE,
79         .major = DRIVER_MAJOR,
80         .minor = DRIVER_MINOR,
81         .patchlevel = DRIVER_PATCHLEVEL,
82
83         .gem_free_object_unlocked =
84                 drm_gem_vram_driver_gem_free_object_unlocked,
85         .dumb_create = mgag200_dumb_create,
86         .dumb_map_offset = drm_gem_vram_driver_dumb_mmap_offset,
87 };
88
89 static struct pci_driver mgag200_pci_driver = {
90         .name = DRIVER_NAME,
91         .id_table = pciidlist,
92         .probe = mga_pci_probe,
93         .remove = mga_pci_remove,
94 };
95
96 static int __init mgag200_init(void)
97 {
98         if (vgacon_text_force() && mgag200_modeset == -1)
99                 return -EINVAL;
100
101         if (mgag200_modeset == 0)
102                 return -EINVAL;
103
104         return pci_register_driver(&mgag200_pci_driver);
105 }
106
107 static void __exit mgag200_exit(void)
108 {
109         pci_unregister_driver(&mgag200_pci_driver);
110 }
111
112 module_init(mgag200_init);
113 module_exit(mgag200_exit);
114
115 MODULE_AUTHOR(DRIVER_AUTHOR);
116 MODULE_DESCRIPTION(DRIVER_DESC);
117 MODULE_LICENSE("GPL");