Thomas Gleixner | c51669e | 2019-05-31 01:09:37 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2012 Red Hat |
| 4 | * |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 5 | * Authors: Matthew Garrett |
| 6 | * Dave Airlie |
| 7 | */ |
Sam Ravnborg | 9f39780 | 2019-06-23 12:35:42 +0200 | [diff] [blame] | 8 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 9 | #include <linux/console.h> |
Thomas Zimmermann | 9623ecb | 2019-12-05 10:02:52 +0100 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/pci.h> |
Sam Ravnborg | 018315d | 2020-08-07 20:05:47 +0200 | [diff] [blame] | 12 | #include <linux/vmalloc.h> |
Sam Ravnborg | 9f39780 | 2019-06-23 12:35:42 +0200 | [diff] [blame] | 13 | |
Thomas Zimmermann | 6848c29 | 2021-04-12 15:10:42 +0200 | [diff] [blame] | 14 | #include <drm/drm_aperture.h> |
Sam Ravnborg | 9f39780 | 2019-06-23 12:35:42 +0200 | [diff] [blame] | 15 | #include <drm/drm_drv.h> |
| 16 | #include <drm/drm_file.h> |
| 17 | #include <drm/drm_ioctl.h> |
Sam Ravnborg | 9f39780 | 2019-06-23 12:35:42 +0200 | [diff] [blame] | 18 | #include <drm/drm_pciids.h> |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 19 | |
| 20 | #include "mgag200_drv.h" |
| 21 | |
Thomas Zimmermann | 913ec47 | 2020-05-15 10:32:33 +0200 | [diff] [blame] | 22 | int mgag200_modeset = -1; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 23 | MODULE_PARM_DESC(modeset, "Disable/Enable modesetting"); |
| 24 | module_param_named(modeset, mgag200_modeset, int, 0400); |
| 25 | |
Thomas Zimmermann | 0987062 | 2020-06-05 15:57:57 +0200 | [diff] [blame] | 26 | /* |
| 27 | * DRM driver |
| 28 | */ |
| 29 | |
| 30 | DEFINE_DRM_GEM_FOPS(mgag200_driver_fops); |
| 31 | |
Daniel Vetter | 70a59dd | 2020-11-04 11:04:24 +0100 | [diff] [blame] | 32 | static const struct drm_driver mgag200_driver = { |
Thomas Zimmermann | 0987062 | 2020-06-05 15:57:57 +0200 | [diff] [blame] | 33 | .driver_features = DRIVER_ATOMIC | DRIVER_GEM | DRIVER_MODESET, |
| 34 | .fops = &mgag200_driver_fops, |
| 35 | .name = DRIVER_NAME, |
| 36 | .desc = DRIVER_DESC, |
| 37 | .date = DRIVER_DATE, |
| 38 | .major = DRIVER_MAJOR, |
| 39 | .minor = DRIVER_MINOR, |
| 40 | .patchlevel = DRIVER_PATCHLEVEL, |
| 41 | DRM_GEM_SHMEM_DRIVER_OPS, |
| 42 | }; |
| 43 | |
| 44 | /* |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 45 | * DRM device |
| 46 | */ |
| 47 | |
Thomas Zimmermann | 4245216 | 2020-07-30 12:28:38 +0200 | [diff] [blame] | 48 | static bool mgag200_has_sgram(struct mga_device *mdev) |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 49 | { |
Thomas Zimmermann | 832eddf | 2020-06-05 15:58:02 +0200 | [diff] [blame] | 50 | struct drm_device *dev = &mdev->base; |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 51 | struct pci_dev *pdev = to_pci_dev(dev->dev); |
Thomas Zimmermann | 4245216 | 2020-07-30 12:28:38 +0200 | [diff] [blame] | 52 | u32 option; |
| 53 | int ret; |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 54 | |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 55 | ret = pci_read_config_dword(pdev, PCI_MGA_OPTION, &option); |
Thomas Zimmermann | 4245216 | 2020-07-30 12:28:38 +0200 | [diff] [blame] | 56 | if (drm_WARN(dev, ret, "failed to read PCI config dword: %d\n", ret)) |
| 57 | return false; |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 58 | |
Thomas Zimmermann | 4245216 | 2020-07-30 12:28:38 +0200 | [diff] [blame] | 59 | return !!(option & PCI_MGA_OPTION_HARDPWMSK); |
| 60 | } |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 61 | |
Thomas Zimmermann | 4245216 | 2020-07-30 12:28:38 +0200 | [diff] [blame] | 62 | static int mgag200_regs_init(struct mga_device *mdev) |
| 63 | { |
| 64 | struct drm_device *dev = &mdev->base; |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 65 | struct pci_dev *pdev = to_pci_dev(dev->dev); |
Thomas Zimmermann | 2021708 | 2020-07-30 12:28:39 +0200 | [diff] [blame] | 66 | u32 option, option2; |
Thomas Zimmermann | 78e5b50 | 2020-07-30 12:28:40 +0200 | [diff] [blame] | 67 | u8 crtcext3; |
Thomas Zimmermann | 4245216 | 2020-07-30 12:28:38 +0200 | [diff] [blame] | 68 | |
Thomas Zimmermann | 2021708 | 2020-07-30 12:28:39 +0200 | [diff] [blame] | 69 | switch (mdev->type) { |
Thomas Zimmermann | e20dfd2 | 2020-07-30 12:28:44 +0200 | [diff] [blame] | 70 | case G200_PCI: |
| 71 | case G200_AGP: |
| 72 | if (mgag200_has_sgram(mdev)) |
| 73 | option = 0x4049cd21; |
| 74 | else |
| 75 | option = 0x40499121; |
| 76 | option2 = 0x00008000; |
| 77 | break; |
Thomas Zimmermann | 2021708 | 2020-07-30 12:28:39 +0200 | [diff] [blame] | 78 | case G200_SE_A: |
| 79 | case G200_SE_B: |
Thomas Zimmermann | d3dc135 | 2020-08-04 08:51:58 +0200 | [diff] [blame] | 80 | option = 0x40049120; |
Thomas Zimmermann | 2021708 | 2020-07-30 12:28:39 +0200 | [diff] [blame] | 81 | if (mgag200_has_sgram(mdev)) |
| 82 | option |= PCI_MGA_OPTION_HARDPWMSK; |
| 83 | option2 = 0x00008000; |
| 84 | break; |
| 85 | case G200_WB: |
| 86 | case G200_EW3: |
| 87 | option = 0x41049120; |
| 88 | option2 = 0x0000b000; |
| 89 | break; |
| 90 | case G200_EV: |
| 91 | option = 0x00000120; |
| 92 | option2 = 0x0000b000; |
| 93 | break; |
| 94 | case G200_EH: |
| 95 | case G200_EH3: |
| 96 | option = 0x00000120; |
| 97 | option2 = 0x0000b000; |
| 98 | break; |
| 99 | default: |
| 100 | option = 0; |
| 101 | option2 = 0; |
| 102 | } |
| 103 | |
| 104 | if (option) |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 105 | pci_write_config_dword(pdev, PCI_MGA_OPTION, option); |
Thomas Zimmermann | 2021708 | 2020-07-30 12:28:39 +0200 | [diff] [blame] | 106 | if (option2) |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 107 | pci_write_config_dword(pdev, PCI_MGA_OPTION2, option2); |
Thomas Zimmermann | 4245216 | 2020-07-30 12:28:38 +0200 | [diff] [blame] | 108 | |
| 109 | /* BAR 1 contains registers */ |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 110 | mdev->rmmio_base = pci_resource_start(pdev, 1); |
| 111 | mdev->rmmio_size = pci_resource_len(pdev, 1); |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 112 | |
| 113 | if (!devm_request_mem_region(dev->dev, mdev->rmmio_base, |
| 114 | mdev->rmmio_size, "mgadrmfb_mmio")) { |
| 115 | drm_err(dev, "can't reserve mmio registers\n"); |
| 116 | return -ENOMEM; |
| 117 | } |
| 118 | |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 119 | mdev->rmmio = pcim_iomap(pdev, 1, 0); |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 120 | if (mdev->rmmio == NULL) |
| 121 | return -ENOMEM; |
| 122 | |
Thomas Zimmermann | 78e5b50 | 2020-07-30 12:28:40 +0200 | [diff] [blame] | 123 | RREG_ECRT(0x03, crtcext3); |
| 124 | crtcext3 |= MGAREG_CRTCEXT3_MGAMODE; |
| 125 | WREG_ECRT(0x03, crtcext3); |
| 126 | |
Thomas Zimmermann | 4245216 | 2020-07-30 12:28:38 +0200 | [diff] [blame] | 127 | return 0; |
| 128 | } |
| 129 | |
Thomas Zimmermann | e20dfd2 | 2020-07-30 12:28:44 +0200 | [diff] [blame] | 130 | static void mgag200_g200_interpret_bios(struct mga_device *mdev, |
| 131 | const unsigned char *bios, |
| 132 | size_t size) |
| 133 | { |
| 134 | static const char matrox[] = {'M', 'A', 'T', 'R', 'O', 'X'}; |
| 135 | static const unsigned int expected_length[6] = { |
| 136 | 0, 64, 64, 64, 128, 128 |
| 137 | }; |
| 138 | struct drm_device *dev = &mdev->base; |
| 139 | const unsigned char *pins; |
| 140 | unsigned int pins_len, version; |
| 141 | int offset; |
| 142 | int tmp; |
| 143 | |
| 144 | /* Test for MATROX string. */ |
| 145 | if (size < 45 + sizeof(matrox)) |
| 146 | return; |
| 147 | if (memcmp(&bios[45], matrox, sizeof(matrox)) != 0) |
| 148 | return; |
| 149 | |
| 150 | /* Get the PInS offset. */ |
| 151 | if (size < MGA_BIOS_OFFSET + 2) |
| 152 | return; |
| 153 | offset = (bios[MGA_BIOS_OFFSET + 1] << 8) | bios[MGA_BIOS_OFFSET]; |
| 154 | |
| 155 | /* Get PInS data structure. */ |
| 156 | |
| 157 | if (size < offset + 6) |
| 158 | return; |
| 159 | pins = bios + offset; |
| 160 | if (pins[0] == 0x2e && pins[1] == 0x41) { |
| 161 | version = pins[5]; |
| 162 | pins_len = pins[2]; |
| 163 | } else { |
| 164 | version = 1; |
| 165 | pins_len = pins[0] + (pins[1] << 8); |
| 166 | } |
| 167 | |
| 168 | if (version < 1 || version > 5) { |
| 169 | drm_warn(dev, "Unknown BIOS PInS version: %d\n", version); |
| 170 | return; |
| 171 | } |
| 172 | if (pins_len != expected_length[version]) { |
Colin Ian King | cd6da0b | 2020-08-26 09:47:27 +0100 | [diff] [blame] | 173 | drm_warn(dev, "Unexpected BIOS PInS size: %d expected: %d\n", |
Thomas Zimmermann | e20dfd2 | 2020-07-30 12:28:44 +0200 | [diff] [blame] | 174 | pins_len, expected_length[version]); |
| 175 | return; |
| 176 | } |
| 177 | if (size < offset + pins_len) |
| 178 | return; |
| 179 | |
| 180 | drm_dbg_kms(dev, "MATROX BIOS PInS version %d size: %d found\n", |
| 181 | version, pins_len); |
| 182 | |
| 183 | /* Extract the clock values */ |
| 184 | |
| 185 | switch (version) { |
| 186 | case 1: |
| 187 | tmp = pins[24] + (pins[25] << 8); |
| 188 | if (tmp) |
| 189 | mdev->model.g200.pclk_max = tmp * 10; |
| 190 | break; |
| 191 | case 2: |
| 192 | if (pins[41] != 0xff) |
| 193 | mdev->model.g200.pclk_max = (pins[41] + 100) * 1000; |
| 194 | break; |
| 195 | case 3: |
| 196 | if (pins[36] != 0xff) |
| 197 | mdev->model.g200.pclk_max = (pins[36] + 100) * 1000; |
| 198 | if (pins[52] & 0x20) |
| 199 | mdev->model.g200.ref_clk = 14318; |
| 200 | break; |
| 201 | case 4: |
| 202 | if (pins[39] != 0xff) |
| 203 | mdev->model.g200.pclk_max = pins[39] * 4 * 1000; |
| 204 | if (pins[92] & 0x01) |
| 205 | mdev->model.g200.ref_clk = 14318; |
| 206 | break; |
| 207 | case 5: |
| 208 | tmp = pins[4] ? 8000 : 6000; |
| 209 | if (pins[123] != 0xff) |
| 210 | mdev->model.g200.pclk_min = pins[123] * tmp; |
| 211 | if (pins[38] != 0xff) |
| 212 | mdev->model.g200.pclk_max = pins[38] * tmp; |
| 213 | if (pins[110] & 0x01) |
| 214 | mdev->model.g200.ref_clk = 14318; |
| 215 | break; |
| 216 | default: |
| 217 | break; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | static void mgag200_g200_init_refclk(struct mga_device *mdev) |
| 222 | { |
| 223 | struct drm_device *dev = &mdev->base; |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 224 | struct pci_dev *pdev = to_pci_dev(dev->dev); |
Thomas Zimmermann | e20dfd2 | 2020-07-30 12:28:44 +0200 | [diff] [blame] | 225 | unsigned char __iomem *rom; |
| 226 | unsigned char *bios; |
| 227 | size_t size; |
| 228 | |
| 229 | mdev->model.g200.pclk_min = 50000; |
| 230 | mdev->model.g200.pclk_max = 230000; |
| 231 | mdev->model.g200.ref_clk = 27050; |
| 232 | |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 233 | rom = pci_map_rom(pdev, &size); |
Thomas Zimmermann | e20dfd2 | 2020-07-30 12:28:44 +0200 | [diff] [blame] | 234 | if (!rom) |
| 235 | return; |
| 236 | |
| 237 | bios = vmalloc(size); |
| 238 | if (!bios) |
| 239 | goto out; |
| 240 | memcpy_fromio(bios, rom, size); |
| 241 | |
| 242 | if (size != 0 && bios[0] == 0x55 && bios[1] == 0xaa) |
| 243 | mgag200_g200_interpret_bios(mdev, bios, size); |
| 244 | |
| 245 | drm_dbg_kms(dev, "pclk_min: %ld pclk_max: %ld ref_clk: %ld\n", |
| 246 | mdev->model.g200.pclk_min, mdev->model.g200.pclk_max, |
| 247 | mdev->model.g200.ref_clk); |
| 248 | |
| 249 | vfree(bios); |
| 250 | out: |
Thomas Zimmermann | 0e6aadc | 2020-12-01 11:35:34 +0100 | [diff] [blame] | 251 | pci_unmap_rom(pdev, rom); |
Thomas Zimmermann | e20dfd2 | 2020-07-30 12:28:44 +0200 | [diff] [blame] | 252 | } |
| 253 | |
Thomas Zimmermann | fb18825 | 2020-07-30 12:28:43 +0200 | [diff] [blame] | 254 | static void mgag200_g200se_init_unique_id(struct mga_device *mdev) |
| 255 | { |
| 256 | struct drm_device *dev = &mdev->base; |
| 257 | |
| 258 | /* stash G200 SE model number for later use */ |
| 259 | mdev->model.g200se.unique_rev_id = RREG32(0x1e24); |
| 260 | |
| 261 | drm_dbg(dev, "G200 SE unique revision id is 0x%x\n", |
| 262 | mdev->model.g200se.unique_rev_id); |
| 263 | } |
| 264 | |
Thomas Zimmermann | 4245216 | 2020-07-30 12:28:38 +0200 | [diff] [blame] | 265 | static int mgag200_device_init(struct mga_device *mdev, unsigned long flags) |
| 266 | { |
| 267 | struct drm_device *dev = &mdev->base; |
| 268 | int ret; |
| 269 | |
| 270 | mdev->flags = mgag200_flags_from_driver_data(flags); |
| 271 | mdev->type = mgag200_type_from_driver_data(flags); |
| 272 | |
| 273 | ret = mgag200_regs_init(mdev); |
| 274 | if (ret) |
| 275 | return ret; |
| 276 | |
Thomas Zimmermann | e20dfd2 | 2020-07-30 12:28:44 +0200 | [diff] [blame] | 277 | if (mdev->type == G200_PCI || mdev->type == G200_AGP) |
| 278 | mgag200_g200_init_refclk(mdev); |
| 279 | else if (IS_G200_SE(mdev)) |
Thomas Zimmermann | fb18825 | 2020-07-30 12:28:43 +0200 | [diff] [blame] | 280 | mgag200_g200se_init_unique_id(mdev); |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 281 | |
| 282 | ret = mgag200_mm_init(mdev); |
| 283 | if (ret) |
Thomas Zimmermann | c714dd9 | 2020-06-05 15:58:00 +0200 | [diff] [blame] | 284 | return ret; |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 285 | |
| 286 | ret = mgag200_modeset_init(mdev); |
| 287 | if (ret) { |
| 288 | drm_err(dev, "Fatal error during modeset init: %d\n", ret); |
Thomas Zimmermann | c714dd9 | 2020-06-05 15:58:00 +0200 | [diff] [blame] | 289 | return ret; |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 290 | } |
| 291 | |
| 292 | return 0; |
Thomas Zimmermann | c714dd9 | 2020-06-05 15:58:00 +0200 | [diff] [blame] | 293 | } |
| 294 | |
Thomas Zimmermann | 3c8923c | 2020-06-05 15:58:01 +0200 | [diff] [blame] | 295 | static struct mga_device * |
Thomas Zimmermann | 832eddf | 2020-06-05 15:58:02 +0200 | [diff] [blame] | 296 | mgag200_device_create(struct pci_dev *pdev, unsigned long flags) |
Thomas Zimmermann | c714dd9 | 2020-06-05 15:58:00 +0200 | [diff] [blame] | 297 | { |
Thomas Zimmermann | 3c8923c | 2020-06-05 15:58:01 +0200 | [diff] [blame] | 298 | struct drm_device *dev; |
Thomas Zimmermann | c714dd9 | 2020-06-05 15:58:00 +0200 | [diff] [blame] | 299 | struct mga_device *mdev; |
| 300 | int ret; |
| 301 | |
Thomas Zimmermann | fb7ba0c | 2020-06-05 15:58:03 +0200 | [diff] [blame] | 302 | mdev = devm_drm_dev_alloc(&pdev->dev, &mgag200_driver, |
| 303 | struct mga_device, base); |
| 304 | if (IS_ERR(mdev)) |
| 305 | return mdev; |
Thomas Zimmermann | 832eddf | 2020-06-05 15:58:02 +0200 | [diff] [blame] | 306 | dev = &mdev->base; |
| 307 | |
Thomas Zimmermann | 3c8923c | 2020-06-05 15:58:01 +0200 | [diff] [blame] | 308 | pci_set_drvdata(pdev, dev); |
| 309 | |
Thomas Zimmermann | c714dd9 | 2020-06-05 15:58:00 +0200 | [diff] [blame] | 310 | ret = mgag200_device_init(mdev, flags); |
| 311 | if (ret) |
Thomas Zimmermann | fb7ba0c | 2020-06-05 15:58:03 +0200 | [diff] [blame] | 312 | return ERR_PTR(ret); |
Thomas Zimmermann | c714dd9 | 2020-06-05 15:58:00 +0200 | [diff] [blame] | 313 | |
Thomas Zimmermann | 3c8923c | 2020-06-05 15:58:01 +0200 | [diff] [blame] | 314 | return mdev; |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 315 | } |
| 316 | |
Thomas Zimmermann | ba5b90e8 | 2020-06-05 15:57:59 +0200 | [diff] [blame] | 317 | /* |
Thomas Zimmermann | 0987062 | 2020-06-05 15:57:57 +0200 | [diff] [blame] | 318 | * PCI driver |
| 319 | */ |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 320 | |
Thomas Zimmermann | fdcb6b1 | 2020-06-05 15:57:58 +0200 | [diff] [blame] | 321 | static const struct pci_device_id mgag200_pciidlist[] = { |
Thomas Zimmermann | e20dfd2 | 2020-07-30 12:28:44 +0200 | [diff] [blame] | 322 | { PCI_VENDOR_ID_MATROX, 0x520, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_PCI }, |
| 323 | { PCI_VENDOR_ID_MATROX, 0x521, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_AGP }, |
Thomas Zimmermann | 4adf0b4 | 2019-12-06 09:19:01 +0100 | [diff] [blame] | 324 | { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, |
Thomas Zimmermann | 1591fad | 2019-11-26 11:15:29 +0100 | [diff] [blame] | 325 | G200_SE_A | MGAG200_FLAG_HW_BUG_NO_STARTADD}, |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 326 | { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B }, |
| 327 | { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV }, |
| 328 | { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB }, |
| 329 | { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH }, |
| 330 | { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER }, |
Mathieu Larouche | 6d857c1 | 2015-08-21 09:24:05 -0400 | [diff] [blame] | 331 | { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 }, |
Mathieu Larouche | f0493e6 | 2016-10-21 12:47:07 -0400 | [diff] [blame] | 332 | { PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 }, |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 333 | {0,} |
| 334 | }; |
| 335 | |
Thomas Zimmermann | fdcb6b1 | 2020-06-05 15:57:58 +0200 | [diff] [blame] | 336 | MODULE_DEVICE_TABLE(pci, mgag200_pciidlist); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 337 | |
Thomas Zimmermann | fdcb6b1 | 2020-06-05 15:57:58 +0200 | [diff] [blame] | 338 | static int |
| 339 | mgag200_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 340 | { |
Thomas Zimmermann | 3c8923c | 2020-06-05 15:58:01 +0200 | [diff] [blame] | 341 | struct mga_device *mdev; |
Thomas Zimmermann | 9623ecb | 2019-12-05 10:02:52 +0100 | [diff] [blame] | 342 | struct drm_device *dev; |
| 343 | int ret; |
| 344 | |
Thomas Zimmermann | 6848c29 | 2021-04-12 15:10:42 +0200 | [diff] [blame] | 345 | ret = drm_aperture_remove_conflicting_pci_framebuffers(pdev, "mgag200drmfb"); |
| 346 | if (ret) |
| 347 | return ret; |
Dave Airlie | 08ef8e4 | 2012-06-01 11:12:39 +0100 | [diff] [blame] | 348 | |
Thomas Zimmermann | 044e093 | 2020-06-05 15:57:52 +0200 | [diff] [blame] | 349 | ret = pcim_enable_device(pdev); |
Thomas Zimmermann | 9623ecb | 2019-12-05 10:02:52 +0100 | [diff] [blame] | 350 | if (ret) |
| 351 | return ret; |
| 352 | |
Thomas Zimmermann | 832eddf | 2020-06-05 15:58:02 +0200 | [diff] [blame] | 353 | mdev = mgag200_device_create(pdev, ent->driver_data); |
Thomas Zimmermann | fb7ba0c | 2020-06-05 15:58:03 +0200 | [diff] [blame] | 354 | if (IS_ERR(mdev)) |
| 355 | return PTR_ERR(mdev); |
Thomas Zimmermann | 832eddf | 2020-06-05 15:58:02 +0200 | [diff] [blame] | 356 | dev = &mdev->base; |
Thomas Zimmermann | 9623ecb | 2019-12-05 10:02:52 +0100 | [diff] [blame] | 357 | |
| 358 | ret = drm_dev_register(dev, ent->driver_data); |
| 359 | if (ret) |
Thomas Zimmermann | fb7ba0c | 2020-06-05 15:58:03 +0200 | [diff] [blame] | 360 | return ret; |
Thomas Zimmermann | 9623ecb | 2019-12-05 10:02:52 +0100 | [diff] [blame] | 361 | |
Thomas Zimmermann | fc54048 | 2020-04-08 10:26:37 +0200 | [diff] [blame] | 362 | drm_fbdev_generic_setup(dev, 0); |
| 363 | |
Thomas Zimmermann | 9623ecb | 2019-12-05 10:02:52 +0100 | [diff] [blame] | 364 | return 0; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 365 | } |
| 366 | |
Thomas Zimmermann | fdcb6b1 | 2020-06-05 15:57:58 +0200 | [diff] [blame] | 367 | static void mgag200_pci_remove(struct pci_dev *pdev) |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 368 | { |
| 369 | struct drm_device *dev = pci_get_drvdata(pdev); |
| 370 | |
Thomas Zimmermann | 9623ecb | 2019-12-05 10:02:52 +0100 | [diff] [blame] | 371 | drm_dev_unregister(dev); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 372 | } |
| 373 | |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 374 | static struct pci_driver mgag200_pci_driver = { |
| 375 | .name = DRIVER_NAME, |
Thomas Zimmermann | fdcb6b1 | 2020-06-05 15:57:58 +0200 | [diff] [blame] | 376 | .id_table = mgag200_pciidlist, |
| 377 | .probe = mgag200_pci_probe, |
| 378 | .remove = mgag200_pci_remove, |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 379 | }; |
| 380 | |
| 381 | static int __init mgag200_init(void) |
| 382 | { |
| 383 | if (vgacon_text_force() && mgag200_modeset == -1) |
| 384 | return -EINVAL; |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 385 | |
| 386 | if (mgag200_modeset == 0) |
| 387 | return -EINVAL; |
Daniel Vetter | 10631d7 | 2017-05-24 16:51:40 +0200 | [diff] [blame] | 388 | |
| 389 | return pci_register_driver(&mgag200_pci_driver); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 390 | } |
| 391 | |
| 392 | static void __exit mgag200_exit(void) |
| 393 | { |
Daniel Vetter | 10631d7 | 2017-05-24 16:51:40 +0200 | [diff] [blame] | 394 | pci_unregister_driver(&mgag200_pci_driver); |
Dave Airlie | 414c453 | 2012-04-17 15:01:25 +0100 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | module_init(mgag200_init); |
| 398 | module_exit(mgag200_exit); |
| 399 | |
| 400 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 401 | MODULE_DESCRIPTION(DRIVER_DESC); |
| 402 | MODULE_LICENSE("GPL"); |