| .. | .. |
|---|
| 25 | 25 | /* |
|---|
| 26 | 26 | * Authors: Dave Airlie <airlied@redhat.com> |
|---|
| 27 | 27 | */ |
|---|
| 28 | | -#include <linux/module.h> |
|---|
| 29 | | -#include <linux/console.h> |
|---|
| 30 | 28 | |
|---|
| 31 | | -#include <drm/drmP.h> |
|---|
| 29 | +#include <linux/console.h> |
|---|
| 30 | +#include <linux/module.h> |
|---|
| 31 | +#include <linux/pci.h> |
|---|
| 32 | + |
|---|
| 33 | +#include <drm/drm_atomic_helper.h> |
|---|
| 32 | 34 | #include <drm/drm_crtc_helper.h> |
|---|
| 35 | +#include <drm/drm_drv.h> |
|---|
| 36 | +#include <drm/drm_fb_helper.h> |
|---|
| 37 | +#include <drm/drm_gem_vram_helper.h> |
|---|
| 38 | +#include <drm/drm_probe_helper.h> |
|---|
| 33 | 39 | |
|---|
| 34 | 40 | #include "ast_drv.h" |
|---|
| 35 | 41 | |
|---|
| .. | .. |
|---|
| 38 | 44 | MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); |
|---|
| 39 | 45 | module_param_named(modeset, ast_modeset, int, 0400); |
|---|
| 40 | 46 | |
|---|
| 41 | | -#define PCI_VENDOR_ASPEED 0x1a03 |
|---|
| 47 | +/* |
|---|
| 48 | + * DRM driver |
|---|
| 49 | + */ |
|---|
| 42 | 50 | |
|---|
| 43 | | -static struct drm_driver driver; |
|---|
| 51 | +DEFINE_DRM_GEM_FOPS(ast_fops); |
|---|
| 52 | + |
|---|
| 53 | +static struct drm_driver ast_driver = { |
|---|
| 54 | + .driver_features = DRIVER_ATOMIC | |
|---|
| 55 | + DRIVER_GEM | |
|---|
| 56 | + DRIVER_MODESET, |
|---|
| 57 | + |
|---|
| 58 | + .fops = &ast_fops, |
|---|
| 59 | + .name = DRIVER_NAME, |
|---|
| 60 | + .desc = DRIVER_DESC, |
|---|
| 61 | + .date = DRIVER_DATE, |
|---|
| 62 | + .major = DRIVER_MAJOR, |
|---|
| 63 | + .minor = DRIVER_MINOR, |
|---|
| 64 | + .patchlevel = DRIVER_PATCHLEVEL, |
|---|
| 65 | + |
|---|
| 66 | + DRM_GEM_VRAM_DRIVER |
|---|
| 67 | +}; |
|---|
| 68 | + |
|---|
| 69 | +/* |
|---|
| 70 | + * PCI driver |
|---|
| 71 | + */ |
|---|
| 72 | + |
|---|
| 73 | +#define PCI_VENDOR_ASPEED 0x1a03 |
|---|
| 44 | 74 | |
|---|
| 45 | 75 | #define AST_VGA_DEVICE(id, info) { \ |
|---|
| 46 | 76 | .class = PCI_BASE_CLASS_DISPLAY << 16, \ |
|---|
| .. | .. |
|---|
| 51 | 81 | .subdevice = PCI_ANY_ID, \ |
|---|
| 52 | 82 | .driver_data = (unsigned long) info } |
|---|
| 53 | 83 | |
|---|
| 54 | | -static const struct pci_device_id pciidlist[] = { |
|---|
| 84 | +static const struct pci_device_id ast_pciidlist[] = { |
|---|
| 55 | 85 | AST_VGA_DEVICE(PCI_CHIP_AST2000, NULL), |
|---|
| 56 | 86 | AST_VGA_DEVICE(PCI_CHIP_AST2100, NULL), |
|---|
| 57 | | - /* AST_VGA_DEVICE(PCI_CHIP_AST1180, NULL), - don't bind to 1180 for now */ |
|---|
| 58 | 87 | {0, 0, 0}, |
|---|
| 59 | 88 | }; |
|---|
| 60 | 89 | |
|---|
| 61 | | -MODULE_DEVICE_TABLE(pci, pciidlist); |
|---|
| 90 | +MODULE_DEVICE_TABLE(pci, ast_pciidlist); |
|---|
| 62 | 91 | |
|---|
| 63 | 92 | static void ast_kick_out_firmware_fb(struct pci_dev *pdev) |
|---|
| 64 | 93 | { |
|---|
| .. | .. |
|---|
| 81 | 110 | |
|---|
| 82 | 111 | static int ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
|---|
| 83 | 112 | { |
|---|
| 113 | + struct ast_private *ast; |
|---|
| 114 | + struct drm_device *dev; |
|---|
| 115 | + int ret; |
|---|
| 116 | + |
|---|
| 84 | 117 | ast_kick_out_firmware_fb(pdev); |
|---|
| 85 | 118 | |
|---|
| 86 | | - return drm_get_pci_dev(pdev, ent, &driver); |
|---|
| 119 | + ret = pcim_enable_device(pdev); |
|---|
| 120 | + if (ret) |
|---|
| 121 | + return ret; |
|---|
| 122 | + |
|---|
| 123 | + ast = ast_device_create(&ast_driver, pdev, ent->driver_data); |
|---|
| 124 | + if (IS_ERR(ast)) |
|---|
| 125 | + return PTR_ERR(ast); |
|---|
| 126 | + dev = &ast->base; |
|---|
| 127 | + |
|---|
| 128 | + ret = drm_dev_register(dev, ent->driver_data); |
|---|
| 129 | + if (ret) |
|---|
| 130 | + return ret; |
|---|
| 131 | + |
|---|
| 132 | + drm_fbdev_generic_setup(dev, 32); |
|---|
| 133 | + |
|---|
| 134 | + return 0; |
|---|
| 87 | 135 | } |
|---|
| 88 | 136 | |
|---|
| 89 | | -static void |
|---|
| 90 | | -ast_pci_remove(struct pci_dev *pdev) |
|---|
| 137 | +static void ast_pci_remove(struct pci_dev *pdev) |
|---|
| 91 | 138 | { |
|---|
| 92 | 139 | struct drm_device *dev = pci_get_drvdata(pdev); |
|---|
| 93 | 140 | |
|---|
| 94 | | - drm_put_dev(dev); |
|---|
| 141 | + drm_dev_unregister(dev); |
|---|
| 142 | + drm_atomic_helper_shutdown(dev); |
|---|
| 95 | 143 | } |
|---|
| 96 | | - |
|---|
| 97 | | - |
|---|
| 98 | 144 | |
|---|
| 99 | 145 | static int ast_drm_freeze(struct drm_device *dev) |
|---|
| 100 | 146 | { |
|---|
| 101 | | - drm_kms_helper_poll_disable(dev); |
|---|
| 147 | + int error; |
|---|
| 102 | 148 | |
|---|
| 149 | + error = drm_mode_config_helper_suspend(dev); |
|---|
| 150 | + if (error) |
|---|
| 151 | + return error; |
|---|
| 103 | 152 | pci_save_state(dev->pdev); |
|---|
| 104 | | - |
|---|
| 105 | | - console_lock(); |
|---|
| 106 | | - ast_fbdev_set_suspend(dev, 1); |
|---|
| 107 | | - console_unlock(); |
|---|
| 108 | 153 | return 0; |
|---|
| 109 | 154 | } |
|---|
| 110 | 155 | |
|---|
| 111 | 156 | static int ast_drm_thaw(struct drm_device *dev) |
|---|
| 112 | 157 | { |
|---|
| 113 | | - int error = 0; |
|---|
| 114 | | - |
|---|
| 115 | 158 | ast_post_gpu(dev); |
|---|
| 116 | 159 | |
|---|
| 117 | | - drm_mode_config_reset(dev); |
|---|
| 118 | | - drm_helper_resume_force_mode(dev); |
|---|
| 119 | | - |
|---|
| 120 | | - console_lock(); |
|---|
| 121 | | - ast_fbdev_set_suspend(dev, 0); |
|---|
| 122 | | - console_unlock(); |
|---|
| 123 | | - return error; |
|---|
| 160 | + return drm_mode_config_helper_resume(dev); |
|---|
| 124 | 161 | } |
|---|
| 125 | 162 | |
|---|
| 126 | 163 | static int ast_drm_resume(struct drm_device *dev) |
|---|
| .. | .. |
|---|
| 133 | 170 | ret = ast_drm_thaw(dev); |
|---|
| 134 | 171 | if (ret) |
|---|
| 135 | 172 | return ret; |
|---|
| 136 | | - |
|---|
| 137 | | - drm_kms_helper_poll_enable(dev); |
|---|
| 138 | 173 | return 0; |
|---|
| 139 | 174 | } |
|---|
| 140 | 175 | |
|---|
| .. | .. |
|---|
| 152 | 187 | pci_set_power_state(pdev, PCI_D3hot); |
|---|
| 153 | 188 | return 0; |
|---|
| 154 | 189 | } |
|---|
| 190 | + |
|---|
| 155 | 191 | static int ast_pm_resume(struct device *dev) |
|---|
| 156 | 192 | { |
|---|
| 157 | 193 | struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| .. | .. |
|---|
| 163 | 199 | { |
|---|
| 164 | 200 | struct pci_dev *pdev = to_pci_dev(dev); |
|---|
| 165 | 201 | struct drm_device *ddev = pci_get_drvdata(pdev); |
|---|
| 166 | | - |
|---|
| 167 | | - if (!ddev || !ddev->dev_private) |
|---|
| 168 | | - return -ENODEV; |
|---|
| 169 | 202 | return ast_drm_freeze(ddev); |
|---|
| 170 | | - |
|---|
| 171 | 203 | } |
|---|
| 172 | 204 | |
|---|
| 173 | 205 | static int ast_pm_thaw(struct device *dev) |
|---|
| .. | .. |
|---|
| 196 | 228 | |
|---|
| 197 | 229 | static struct pci_driver ast_pci_driver = { |
|---|
| 198 | 230 | .name = DRIVER_NAME, |
|---|
| 199 | | - .id_table = pciidlist, |
|---|
| 231 | + .id_table = ast_pciidlist, |
|---|
| 200 | 232 | .probe = ast_pci_probe, |
|---|
| 201 | 233 | .remove = ast_pci_remove, |
|---|
| 202 | 234 | .driver.pm = &ast_pm_ops, |
|---|
| 203 | | -}; |
|---|
| 204 | | - |
|---|
| 205 | | -static const struct file_operations ast_fops = { |
|---|
| 206 | | - .owner = THIS_MODULE, |
|---|
| 207 | | - .open = drm_open, |
|---|
| 208 | | - .release = drm_release, |
|---|
| 209 | | - .unlocked_ioctl = drm_ioctl, |
|---|
| 210 | | - .mmap = ast_mmap, |
|---|
| 211 | | - .poll = drm_poll, |
|---|
| 212 | | - .compat_ioctl = drm_compat_ioctl, |
|---|
| 213 | | - .read = drm_read, |
|---|
| 214 | | -}; |
|---|
| 215 | | - |
|---|
| 216 | | -static struct drm_driver driver = { |
|---|
| 217 | | - .driver_features = DRIVER_MODESET | DRIVER_GEM, |
|---|
| 218 | | - |
|---|
| 219 | | - .load = ast_driver_load, |
|---|
| 220 | | - .unload = ast_driver_unload, |
|---|
| 221 | | - |
|---|
| 222 | | - .fops = &ast_fops, |
|---|
| 223 | | - .name = DRIVER_NAME, |
|---|
| 224 | | - .desc = DRIVER_DESC, |
|---|
| 225 | | - .date = DRIVER_DATE, |
|---|
| 226 | | - .major = DRIVER_MAJOR, |
|---|
| 227 | | - .minor = DRIVER_MINOR, |
|---|
| 228 | | - .patchlevel = DRIVER_PATCHLEVEL, |
|---|
| 229 | | - |
|---|
| 230 | | - .gem_free_object_unlocked = ast_gem_free_object, |
|---|
| 231 | | - .dumb_create = ast_dumb_create, |
|---|
| 232 | | - .dumb_map_offset = ast_dumb_mmap_offset, |
|---|
| 233 | | - |
|---|
| 234 | 235 | }; |
|---|
| 235 | 236 | |
|---|
| 236 | 237 | static int __init ast_init(void) |
|---|
| .. | .. |
|---|
| 253 | 254 | MODULE_AUTHOR(DRIVER_AUTHOR); |
|---|
| 254 | 255 | MODULE_DESCRIPTION(DRIVER_DESC); |
|---|
| 255 | 256 | MODULE_LICENSE("GPL and additional rights"); |
|---|
| 256 | | - |
|---|