]>
Commit | Line | Data |
---|---|---|
f9aa76a8 DA |
1 | /* |
2 | * Copyright 2012 Red Hat <mjg@redhat.com> | |
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> | |
760285e7 | 13 | #include <drm/drmP.h> |
2f1e8007 | 14 | #include <drm/drm_crtc_helper.h> |
fcd70cd3 | 15 | #include <drm/drm_probe_helper.h> |
f9aa76a8 DA |
16 | |
17 | #include "cirrus_drv.h" | |
18 | ||
19 | int cirrus_modeset = -1; | |
550f1744 | 20 | int cirrus_bpp = 16; |
f9aa76a8 DA |
21 | |
22 | MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); | |
23 | module_param_named(modeset, cirrus_modeset, int, 0400); | |
550f1744 | 24 | MODULE_PARM_DESC(bpp, "Max bits-per-pixel (default:16)"); |
7f551b1e | 25 | module_param_named(bpp, cirrus_bpp, int, 0400); |
f9aa76a8 DA |
26 | |
27 | /* | |
28 | * This is the generic driver code. This binds the driver to the drm core, | |
29 | * which then performs further device association and calls our graphics init | |
30 | * functions | |
31 | */ | |
32 | ||
33 | static struct drm_driver driver; | |
34 | ||
35 | /* only bind to the cirrus chip in qemu */ | |
9baa3c34 | 36 | static const struct pci_device_id pciidlist[] = { |
caf02abf RJ |
37 | { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, |
38 | PCI_SUBVENDOR_ID_REDHAT_QUMRANET, PCI_SUBDEVICE_ID_QEMU, | |
39 | 0, 0, 0 }, | |
c0c3e735 OH |
40 | { PCI_VENDOR_ID_CIRRUS, PCI_DEVICE_ID_CIRRUS_5446, PCI_VENDOR_ID_XEN, |
41 | 0x0001, 0, 0, 0 }, | |
f9aa76a8 DA |
42 | {0,} |
43 | }; | |
44 | ||
dedc14e2 | 45 | |
56550d94 GKH |
46 | static int cirrus_pci_probe(struct pci_dev *pdev, |
47 | const struct pci_device_id *ent) | |
f9aa76a8 | 48 | { |
bfb82ff0 TR |
49 | int ret; |
50 | ||
256ee417 | 51 | ret = drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "cirrusdrmfb"); |
bfb82ff0 TR |
52 | if (ret) |
53 | return ret; | |
dedc14e2 | 54 | |
f9aa76a8 DA |
55 | return drm_get_pci_dev(pdev, ent, &driver); |
56 | } | |
57 | ||
58 | static void cirrus_pci_remove(struct pci_dev *pdev) | |
59 | { | |
60 | struct drm_device *dev = pci_get_drvdata(pdev); | |
61 | ||
62 | drm_put_dev(dev); | |
63 | } | |
64 | ||
8f8e7e14 | 65 | #ifdef CONFIG_PM_SLEEP |
2f1e8007 GH |
66 | static int cirrus_pm_suspend(struct device *dev) |
67 | { | |
68 | struct pci_dev *pdev = to_pci_dev(dev); | |
69 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
70 | struct cirrus_device *cdev = drm_dev->dev_private; | |
71 | ||
72 | drm_kms_helper_poll_disable(drm_dev); | |
73 | ||
74 | if (cdev->mode_info.gfbdev) { | |
75 | console_lock(); | |
2b9e6e37 | 76 | drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 1); |
2f1e8007 GH |
77 | console_unlock(); |
78 | } | |
79 | ||
80 | return 0; | |
81 | } | |
82 | ||
83 | static int cirrus_pm_resume(struct device *dev) | |
84 | { | |
85 | struct pci_dev *pdev = to_pci_dev(dev); | |
86 | struct drm_device *drm_dev = pci_get_drvdata(pdev); | |
87 | struct cirrus_device *cdev = drm_dev->dev_private; | |
88 | ||
89 | drm_helper_resume_force_mode(drm_dev); | |
90 | ||
91 | if (cdev->mode_info.gfbdev) { | |
92 | console_lock(); | |
2b9e6e37 | 93 | drm_fb_helper_set_suspend(&cdev->mode_info.gfbdev->helper, 0); |
2f1e8007 GH |
94 | console_unlock(); |
95 | } | |
96 | ||
97 | drm_kms_helper_poll_enable(drm_dev); | |
98 | return 0; | |
99 | } | |
8f8e7e14 | 100 | #endif |
2f1e8007 | 101 | |
f9aa76a8 DA |
102 | static const struct file_operations cirrus_driver_fops = { |
103 | .owner = THIS_MODULE, | |
104 | .open = drm_open, | |
105 | .release = drm_release, | |
106 | .unlocked_ioctl = drm_ioctl, | |
107 | .mmap = cirrus_mmap, | |
108 | .poll = drm_poll, | |
804d74ab | 109 | .compat_ioctl = drm_compat_ioctl, |
f9aa76a8 DA |
110 | }; |
111 | static struct drm_driver driver = { | |
28185647 | 112 | .driver_features = DRIVER_MODESET | DRIVER_GEM, |
f9aa76a8 DA |
113 | .load = cirrus_driver_load, |
114 | .unload = cirrus_driver_unload, | |
115 | .fops = &cirrus_driver_fops, | |
116 | .name = DRIVER_NAME, | |
117 | .desc = DRIVER_DESC, | |
118 | .date = DRIVER_DATE, | |
119 | .major = DRIVER_MAJOR, | |
120 | .minor = DRIVER_MINOR, | |
121 | .patchlevel = DRIVER_PATCHLEVEL, | |
f5993eeb | 122 | .gem_free_object_unlocked = cirrus_gem_free_object, |
f9aa76a8 DA |
123 | .dumb_create = cirrus_dumb_create, |
124 | .dumb_map_offset = cirrus_dumb_mmap_offset, | |
f9aa76a8 DA |
125 | }; |
126 | ||
2f1e8007 GH |
127 | static const struct dev_pm_ops cirrus_pm_ops = { |
128 | SET_SYSTEM_SLEEP_PM_OPS(cirrus_pm_suspend, | |
129 | cirrus_pm_resume) | |
130 | }; | |
131 | ||
f9aa76a8 DA |
132 | static struct pci_driver cirrus_pci_driver = { |
133 | .name = DRIVER_NAME, | |
134 | .id_table = pciidlist, | |
135 | .probe = cirrus_pci_probe, | |
136 | .remove = cirrus_pci_remove, | |
2f1e8007 | 137 | .driver.pm = &cirrus_pm_ops, |
f9aa76a8 DA |
138 | }; |
139 | ||
140 | static int __init cirrus_init(void) | |
141 | { | |
142 | if (vgacon_text_force() && cirrus_modeset == -1) | |
143 | return -EINVAL; | |
144 | ||
145 | if (cirrus_modeset == 0) | |
146 | return -EINVAL; | |
10631d72 | 147 | return pci_register_driver(&cirrus_pci_driver); |
f9aa76a8 DA |
148 | } |
149 | ||
150 | static void __exit cirrus_exit(void) | |
151 | { | |
10631d72 | 152 | pci_unregister_driver(&cirrus_pci_driver); |
f9aa76a8 DA |
153 | } |
154 | ||
155 | module_init(cirrus_init); | |
156 | module_exit(cirrus_exit); | |
157 | ||
158 | MODULE_DEVICE_TABLE(pci, pciidlist); | |
159 | MODULE_AUTHOR(DRIVER_AUTHOR); | |
160 | MODULE_DESCRIPTION(DRIVER_DESC); | |
161 | MODULE_LICENSE("GPL"); |