blob: 3c8e04f54713b7964c5c915f3b06ca1a70f54578 [file] [log] [blame]
Dave Airlie414c4532012-04-17 15:01:25 +01001/*
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 "drmP.h"
14#include "drm.h"
15
16#include "mgag200_drv.h"
17
18#include "drm_pciids.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 */
25int mgag200_modeset = -1;
26
27MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
28module_param_named(modeset, mgag200_modeset, int, 0400);
29
30static struct drm_driver driver;
31
32static DEFINE_PCI_DEVICE_TABLE(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 {0,}
40};
41
42MODULE_DEVICE_TABLE(pci, pciidlist);
43
44static int __devinit
45mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46{
47 return drm_get_pci_dev(pdev, ent, &driver);
48}
49
50static void mga_pci_remove(struct pci_dev *pdev)
51{
52 struct drm_device *dev = pci_get_drvdata(pdev);
53
54 drm_put_dev(dev);
55}
56
57static const struct file_operations mgag200_driver_fops = {
58 .owner = THIS_MODULE,
59 .open = drm_open,
60 .release = drm_release,
61 .unlocked_ioctl = drm_ioctl,
62 .mmap = mgag200_mmap,
63 .poll = drm_poll,
64 .fasync = drm_fasync,
65 .read = drm_read,
66};
67
68static struct drm_driver driver = {
69 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_USE_MTRR,
70 .load = mgag200_driver_load,
71 .unload = mgag200_driver_unload,
72 .fops = &mgag200_driver_fops,
73 .name = DRIVER_NAME,
74 .desc = DRIVER_DESC,
75 .date = DRIVER_DATE,
76 .major = DRIVER_MAJOR,
77 .minor = DRIVER_MINOR,
78 .patchlevel = DRIVER_PATCHLEVEL,
79
80 .gem_init_object = mgag200_gem_init_object,
81 .gem_free_object = mgag200_gem_free_object,
82 .dumb_create = mgag200_dumb_create,
83 .dumb_map_offset = mgag200_dumb_mmap_offset,
84 .dumb_destroy = mgag200_dumb_destroy,
85};
86
87static struct pci_driver mgag200_pci_driver = {
88 .name = DRIVER_NAME,
89 .id_table = pciidlist,
90 .probe = mga_pci_probe,
91 .remove = mga_pci_remove,
92};
93
94static int __init mgag200_init(void)
95{
Dave Airlie4688a692012-05-19 16:33:21 +010096#ifdef CONFIG_VGA_CONSOLE
Dave Airlie414c4532012-04-17 15:01:25 +010097 if (vgacon_text_force() && mgag200_modeset == -1)
98 return -EINVAL;
Dave Airlie4688a692012-05-19 16:33:21 +010099#endif
Dave Airlie414c4532012-04-17 15:01:25 +0100100
101 if (mgag200_modeset == 0)
102 return -EINVAL;
103 return drm_pci_init(&driver, &mgag200_pci_driver);
104}
105
106static void __exit mgag200_exit(void)
107{
108 drm_pci_exit(&driver, &mgag200_pci_driver);
109}
110
111module_init(mgag200_init);
112module_exit(mgag200_exit);
113
114MODULE_AUTHOR(DRIVER_AUTHOR);
115MODULE_DESCRIPTION(DRIVER_DESC);
116MODULE_LICENSE("GPL");