cirrus_drv.c 3.8 KB

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