2 * Copyright 2012 Red Hat Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sub license, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
15 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
16 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
17 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
18 * USE OR OTHER DEALINGS IN THE SOFTWARE.
20 * The above copyright notice and this permission notice (including the
21 * next paragraph) shall be included in all copies or substantial portions
29 #include <linux/module.h>
30 #include <linux/pci.h>
32 #include <drm/drm_aperture.h>
33 #include <drm/drm_atomic_helper.h>
34 #include <drm/drm_crtc_helper.h>
35 #include <drm/drm_drv.h>
36 #include <drm/drm_gem_vram_helper.h>
37 #include <drm/drm_probe_helper.h>
43 MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
44 module_param_named(modeset, ast_modeset, int, 0400);
50 DEFINE_DRM_GEM_FOPS(ast_fops);
52 static const struct drm_driver ast_driver = {
53 .driver_features = DRIVER_ATOMIC |
61 .major = DRIVER_MAJOR,
62 .minor = DRIVER_MINOR,
63 .patchlevel = DRIVER_PATCHLEVEL,
72 #define PCI_VENDOR_ASPEED 0x1a03
74 #define AST_VGA_DEVICE(id, info) { \
75 .class = PCI_BASE_CLASS_DISPLAY << 16, \
76 .class_mask = 0xff0000, \
77 .vendor = PCI_VENDOR_ASPEED, \
79 .subvendor = PCI_ANY_ID, \
80 .subdevice = PCI_ANY_ID, \
81 .driver_data = (unsigned long) info }
83 static const struct pci_device_id ast_pciidlist[] = {
84 AST_VGA_DEVICE(PCI_CHIP_AST2000, NULL),
85 AST_VGA_DEVICE(PCI_CHIP_AST2100, NULL),
89 MODULE_DEVICE_TABLE(pci, ast_pciidlist);
91 static int ast_remove_conflicting_framebuffers(struct pci_dev *pdev)
94 resource_size_t base, size;
96 base = pci_resource_start(pdev, 0);
97 size = pci_resource_len(pdev, 0);
99 primary = pdev->resource[PCI_ROM_RESOURCE].flags & IORESOURCE_ROM_SHADOW;
102 return drm_aperture_remove_conflicting_framebuffers(base, size, primary, &ast_driver);
105 static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
107 struct ast_private *ast;
108 struct drm_device *dev;
111 ret = ast_remove_conflicting_framebuffers(pdev);
115 ret = pcim_enable_device(pdev);
119 ast = ast_device_create(&ast_driver, pdev, ent->driver_data);
124 ret = drm_dev_register(dev, ent->driver_data);
128 drm_fbdev_generic_setup(dev, 32);
133 static void ast_pci_remove(struct pci_dev *pdev)
135 struct drm_device *dev = pci_get_drvdata(pdev);
137 drm_dev_unregister(dev);
138 drm_atomic_helper_shutdown(dev);
141 static int ast_drm_freeze(struct drm_device *dev)
145 error = drm_mode_config_helper_suspend(dev);
148 pci_save_state(to_pci_dev(dev->dev));
152 static int ast_drm_thaw(struct drm_device *dev)
156 return drm_mode_config_helper_resume(dev);
159 static int ast_drm_resume(struct drm_device *dev)
163 if (pci_enable_device(to_pci_dev(dev->dev)))
166 ret = ast_drm_thaw(dev);
172 static int ast_pm_suspend(struct device *dev)
174 struct pci_dev *pdev = to_pci_dev(dev);
175 struct drm_device *ddev = pci_get_drvdata(pdev);
178 error = ast_drm_freeze(ddev);
182 pci_disable_device(pdev);
183 pci_set_power_state(pdev, PCI_D3hot);
187 static int ast_pm_resume(struct device *dev)
189 struct pci_dev *pdev = to_pci_dev(dev);
190 struct drm_device *ddev = pci_get_drvdata(pdev);
191 return ast_drm_resume(ddev);
194 static int ast_pm_freeze(struct device *dev)
196 struct pci_dev *pdev = to_pci_dev(dev);
197 struct drm_device *ddev = pci_get_drvdata(pdev);
198 return ast_drm_freeze(ddev);
201 static int ast_pm_thaw(struct device *dev)
203 struct pci_dev *pdev = to_pci_dev(dev);
204 struct drm_device *ddev = pci_get_drvdata(pdev);
205 return ast_drm_thaw(ddev);
208 static int ast_pm_poweroff(struct device *dev)
210 struct pci_dev *pdev = to_pci_dev(dev);
211 struct drm_device *ddev = pci_get_drvdata(pdev);
213 return ast_drm_freeze(ddev);
216 static const struct dev_pm_ops ast_pm_ops = {
217 .suspend = ast_pm_suspend,
218 .resume = ast_pm_resume,
219 .freeze = ast_pm_freeze,
221 .poweroff = ast_pm_poweroff,
222 .restore = ast_pm_resume,
225 static struct pci_driver ast_pci_driver = {
227 .id_table = ast_pciidlist,
228 .probe = ast_pci_probe,
229 .remove = ast_pci_remove,
230 .driver.pm = &ast_pm_ops,
233 static int __init ast_init(void)
235 if (drm_firmware_drivers_only() && ast_modeset == -1)
238 if (ast_modeset == 0)
240 return pci_register_driver(&ast_pci_driver);
242 static void __exit ast_exit(void)
244 pci_unregister_driver(&ast_pci_driver);
247 module_init(ast_init);
248 module_exit(ast_exit);
250 MODULE_AUTHOR(DRIVER_AUTHOR);
251 MODULE_DESCRIPTION(DRIVER_DESC);
252 MODULE_LICENSE("GPL and additional rights");