Merge branch 'samsung/pinctrl' into next/dt2
[GitHub/mt8127/android_kernel_alcatel_ttab.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 "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 */
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 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
42 MODULE_DEVICE_TABLE(pci, pciidlist);
43
44 static void mgag200_kick_out_firmware_fb(struct pci_dev *pdev)
45 {
46 struct apertures_struct *ap;
47 bool primary = false;
48
49 ap = alloc_apertures(1);
50 if (!ap)
51 return;
52
53 ap->ranges[0].base = pci_resource_start(pdev, 0);
54 ap->ranges[0].size = pci_resource_len(pdev, 0);
55
56 #ifdef CONFIG_X86
57 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
58 #endif
59 remove_conflicting_framebuffers(ap, "mgag200drmfb", primary);
60 kfree(ap);
61 }
62
63
64 static int __devinit
65 mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
66 {
67 mgag200_kick_out_firmware_fb(pdev);
68
69 return drm_get_pci_dev(pdev, ent, &driver);
70 }
71
72 static void mga_pci_remove(struct pci_dev *pdev)
73 {
74 struct drm_device *dev = pci_get_drvdata(pdev);
75
76 drm_put_dev(dev);
77 }
78
79 static const struct file_operations mgag200_driver_fops = {
80 .owner = THIS_MODULE,
81 .open = drm_open,
82 .release = drm_release,
83 .unlocked_ioctl = drm_ioctl,
84 .mmap = mgag200_mmap,
85 .poll = drm_poll,
86 .fasync = drm_fasync,
87 #ifdef CONFIG_COMPAT
88 .compat_ioctl = drm_compat_ioctl,
89 #endif
90 .read = drm_read,
91 };
92
93 static struct drm_driver driver = {
94 .driver_features = DRIVER_GEM | DRIVER_MODESET | DRIVER_USE_MTRR,
95 .load = mgag200_driver_load,
96 .unload = mgag200_driver_unload,
97 .fops = &mgag200_driver_fops,
98 .name = DRIVER_NAME,
99 .desc = DRIVER_DESC,
100 .date = DRIVER_DATE,
101 .major = DRIVER_MAJOR,
102 .minor = DRIVER_MINOR,
103 .patchlevel = DRIVER_PATCHLEVEL,
104
105 .gem_init_object = mgag200_gem_init_object,
106 .gem_free_object = mgag200_gem_free_object,
107 .dumb_create = mgag200_dumb_create,
108 .dumb_map_offset = mgag200_dumb_mmap_offset,
109 .dumb_destroy = mgag200_dumb_destroy,
110 };
111
112 static struct pci_driver mgag200_pci_driver = {
113 .name = DRIVER_NAME,
114 .id_table = pciidlist,
115 .probe = mga_pci_probe,
116 .remove = mga_pci_remove,
117 };
118
119 static int __init mgag200_init(void)
120 {
121 #ifdef CONFIG_VGA_CONSOLE
122 if (vgacon_text_force() && mgag200_modeset == -1)
123 return -EINVAL;
124 #endif
125
126 if (mgag200_modeset == 0)
127 return -EINVAL;
128 return drm_pci_init(&driver, &mgag200_pci_driver);
129 }
130
131 static void __exit mgag200_exit(void)
132 {
133 drm_pci_exit(&driver, &mgag200_pci_driver);
134 }
135
136 module_init(mgag200_init);
137 module_exit(mgag200_exit);
138
139 MODULE_AUTHOR(DRIVER_AUTHOR);
140 MODULE_DESCRIPTION(DRIVER_DESC);
141 MODULE_LICENSE("GPL");