mgag200_drv.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright 2012 Red Hat
  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>
  13. #include <drm/drmP.h>
  14. #include "mgag200_drv.h"
  15. #include <drm/drm_pciids.h>
  16. /*
  17. * This is the generic driver code. This binds the driver to the drm core,
  18. * which then performs further device association and calls our graphics init
  19. * functions
  20. */
  21. int mgag200_modeset = -1;
  22. MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
  23. module_param_named(modeset, mgag200_modeset, int, 0400);
  24. static struct drm_driver driver;
  25. static const struct pci_device_id pciidlist[] = {
  26. { PCI_VENDOR_ID_MATROX, 0x522, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_A },
  27. { PCI_VENDOR_ID_MATROX, 0x524, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_SE_B },
  28. { PCI_VENDOR_ID_MATROX, 0x530, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EV },
  29. { PCI_VENDOR_ID_MATROX, 0x532, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_WB },
  30. { PCI_VENDOR_ID_MATROX, 0x533, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH },
  31. { PCI_VENDOR_ID_MATROX, 0x534, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_ER },
  32. { PCI_VENDOR_ID_MATROX, 0x536, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EW3 },
  33. { PCI_VENDOR_ID_MATROX, 0x538, PCI_ANY_ID, PCI_ANY_ID, 0, 0, G200_EH3 },
  34. {0,}
  35. };
  36. MODULE_DEVICE_TABLE(pci, pciidlist);
  37. static int mga_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  38. {
  39. drm_fb_helper_remove_conflicting_pci_framebuffers(pdev, 0, "mgag200drmfb");
  40. return drm_get_pci_dev(pdev, ent, &driver);
  41. }
  42. static void mga_pci_remove(struct pci_dev *pdev)
  43. {
  44. struct drm_device *dev = pci_get_drvdata(pdev);
  45. drm_put_dev(dev);
  46. }
  47. static const struct file_operations mgag200_driver_fops = {
  48. .owner = THIS_MODULE,
  49. .open = drm_open,
  50. .release = drm_release,
  51. .unlocked_ioctl = drm_ioctl,
  52. .mmap = mgag200_mmap,
  53. .poll = drm_poll,
  54. .compat_ioctl = drm_compat_ioctl,
  55. .read = drm_read,
  56. };
  57. static struct drm_driver driver = {
  58. .driver_features = DRIVER_GEM | DRIVER_MODESET,
  59. .load = mgag200_driver_load,
  60. .unload = mgag200_driver_unload,
  61. .fops = &mgag200_driver_fops,
  62. .name = DRIVER_NAME,
  63. .desc = DRIVER_DESC,
  64. .date = DRIVER_DATE,
  65. .major = DRIVER_MAJOR,
  66. .minor = DRIVER_MINOR,
  67. .patchlevel = DRIVER_PATCHLEVEL,
  68. .gem_free_object_unlocked = mgag200_gem_free_object,
  69. .dumb_create = mgag200_dumb_create,
  70. .dumb_map_offset = mgag200_dumb_mmap_offset,
  71. };
  72. static struct pci_driver mgag200_pci_driver = {
  73. .name = DRIVER_NAME,
  74. .id_table = pciidlist,
  75. .probe = mga_pci_probe,
  76. .remove = mga_pci_remove,
  77. };
  78. static int __init mgag200_init(void)
  79. {
  80. if (vgacon_text_force() && mgag200_modeset == -1)
  81. return -EINVAL;
  82. if (mgag200_modeset == 0)
  83. return -EINVAL;
  84. return pci_register_driver(&mgag200_pci_driver);
  85. }
  86. static void __exit mgag200_exit(void)
  87. {
  88. pci_unregister_driver(&mgag200_pci_driver);
  89. }
  90. module_init(mgag200_init);
  91. module_exit(mgag200_exit);
  92. MODULE_AUTHOR(DRIVER_AUTHOR);
  93. MODULE_DESCRIPTION(DRIVER_DESC);
  94. MODULE_LICENSE("GPL");