OSDN Git Service

drm/tilcdc: Remove obsolete bundled tilcdc tfp410 driver
[uclinux-h8/linux.git] / drivers / gpu / drm / mgag200 / mgag200_drv.c
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/console.h>
10 #include <linux/module.h>
11 #include <linux/pci.h>
12
13 #include <drm/drm_drv.h>
14 #include <drm/drm_file.h>
15 #include <drm/drm_ioctl.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         struct drm_device *dev;
50         int ret;
51
52         drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, "mgag200drmfb");
53
54         ret = pci_enable_device(pdev);
55         if (ret)
56                 return ret;
57
58         dev = drm_dev_alloc(&driver, &pdev->dev);
59         if (IS_ERR(dev)) {
60                 ret = PTR_ERR(dev);
61                 goto err_pci_disable_device;
62         }
63
64         dev->pdev = pdev;
65         pci_set_drvdata(pdev, dev);
66
67         ret = mgag200_driver_load(dev, ent->driver_data);
68         if (ret)
69                 goto err_drm_dev_put;
70
71         ret = drm_dev_register(dev, ent->driver_data);
72         if (ret)
73                 goto err_mgag200_driver_unload;
74
75         return 0;
76
77 err_mgag200_driver_unload:
78         mgag200_driver_unload(dev);
79 err_drm_dev_put:
80         drm_dev_put(dev);
81 err_pci_disable_device:
82         pci_disable_device(pdev);
83         return ret;
84 }
85
86 static void mga_pci_remove(struct pci_dev *pdev)
87 {
88         struct drm_device *dev = pci_get_drvdata(pdev);
89
90         drm_dev_unregister(dev);
91         mgag200_driver_unload(dev);
92         drm_dev_put(dev);
93 }
94
95 DEFINE_DRM_GEM_FOPS(mgag200_driver_fops);
96
97 static struct drm_driver driver = {
98         .driver_features = DRIVER_GEM | DRIVER_MODESET,
99         .fops = &mgag200_driver_fops,
100         .name = DRIVER_NAME,
101         .desc = DRIVER_DESC,
102         .date = DRIVER_DATE,
103         .major = DRIVER_MAJOR,
104         .minor = DRIVER_MINOR,
105         .patchlevel = DRIVER_PATCHLEVEL,
106         DRM_GEM_VRAM_DRIVER
107 };
108
109 static struct pci_driver mgag200_pci_driver = {
110         .name = DRIVER_NAME,
111         .id_table = pciidlist,
112         .probe = mga_pci_probe,
113         .remove = mga_pci_remove,
114 };
115
116 static int __init mgag200_init(void)
117 {
118         if (vgacon_text_force() && mgag200_modeset == -1)
119                 return -EINVAL;
120
121         if (mgag200_modeset == 0)
122                 return -EINVAL;
123
124         return pci_register_driver(&mgag200_pci_driver);
125 }
126
127 static void __exit mgag200_exit(void)
128 {
129         pci_unregister_driver(&mgag200_pci_driver);
130 }
131
132 module_init(mgag200_init);
133 module_exit(mgag200_exit);
134
135 MODULE_AUTHOR(DRIVER_AUTHOR);
136 MODULE_DESCRIPTION(DRIVER_DESC);
137 MODULE_LICENSE("GPL");