ast_drv.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright 2012 Red Hat Inc.
  3. *
  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:
  11. *
  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.
  19. *
  20. * The above copyright notice and this permission notice (including the
  21. * next paragraph) shall be included in all copies or substantial portions
  22. * of the Software.
  23. *
  24. */
  25. /*
  26. * Authors: Dave Airlie <airlied@redhat.com>
  27. */
  28. #include <linux/module.h>
  29. #include <linux/console.h>
  30. #include "drmP.h"
  31. #include "drm.h"
  32. #include "drm_crtc_helper.h"
  33. #include "ast_drv.h"
  34. int ast_modeset = -1;
  35. MODULE_PARM_DESC(modeset, "Disable/Enable modesetting");
  36. module_param_named(modeset, ast_modeset, int, 0400);
  37. #define PCI_VENDOR_ASPEED 0x1a03
  38. static struct drm_driver driver;
  39. #define AST_VGA_DEVICE(id, info) { \
  40. .class = PCI_BASE_CLASS_DISPLAY << 16, \
  41. .class_mask = 0xff0000, \
  42. .vendor = PCI_VENDOR_ASPEED, \
  43. .device = id, \
  44. .subvendor = PCI_ANY_ID, \
  45. .subdevice = PCI_ANY_ID, \
  46. .driver_data = (unsigned long) info }
  47. static DEFINE_PCI_DEVICE_TABLE(pciidlist) = {
  48. AST_VGA_DEVICE(PCI_CHIP_AST2000, NULL),
  49. AST_VGA_DEVICE(PCI_CHIP_AST2100, NULL),
  50. /* AST_VGA_DEVICE(PCI_CHIP_AST1180, NULL), - don't bind to 1180 for now */
  51. {0, 0, 0},
  52. };
  53. MODULE_DEVICE_TABLE(pci, pciidlist);
  54. static int __devinit
  55. ast_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
  56. {
  57. return drm_get_pci_dev(pdev, ent, &driver);
  58. }
  59. static void
  60. ast_pci_remove(struct pci_dev *pdev)
  61. {
  62. struct drm_device *dev = pci_get_drvdata(pdev);
  63. drm_put_dev(dev);
  64. }
  65. static int ast_drm_freeze(struct drm_device *dev)
  66. {
  67. drm_kms_helper_poll_disable(dev);
  68. pci_save_state(dev->pdev);
  69. console_lock();
  70. ast_fbdev_set_suspend(dev, 1);
  71. console_unlock();
  72. return 0;
  73. }
  74. static int ast_drm_thaw(struct drm_device *dev)
  75. {
  76. int error = 0;
  77. ast_post_gpu(dev);
  78. drm_mode_config_reset(dev);
  79. mutex_lock(&dev->mode_config.mutex);
  80. drm_helper_resume_force_mode(dev);
  81. mutex_unlock(&dev->mode_config.mutex);
  82. console_lock();
  83. ast_fbdev_set_suspend(dev, 0);
  84. console_unlock();
  85. return error;
  86. }
  87. static int ast_drm_resume(struct drm_device *dev)
  88. {
  89. int ret;
  90. if (pci_enable_device(dev->pdev))
  91. return -EIO;
  92. ret = ast_drm_thaw(dev);
  93. if (ret)
  94. return ret;
  95. drm_kms_helper_poll_enable(dev);
  96. return 0;
  97. }
  98. static int ast_pm_suspend(struct device *dev)
  99. {
  100. struct pci_dev *pdev = to_pci_dev(dev);
  101. struct drm_device *ddev = pci_get_drvdata(pdev);
  102. int error;
  103. error = ast_drm_freeze(ddev);
  104. if (error)
  105. return error;
  106. pci_disable_device(pdev);
  107. pci_set_power_state(pdev, PCI_D3hot);
  108. return 0;
  109. }
  110. static int ast_pm_resume(struct device *dev)
  111. {
  112. struct pci_dev *pdev = to_pci_dev(dev);
  113. struct drm_device *ddev = pci_get_drvdata(pdev);
  114. return ast_drm_resume(ddev);
  115. }
  116. static int ast_pm_freeze(struct device *dev)
  117. {
  118. struct pci_dev *pdev = to_pci_dev(dev);
  119. struct drm_device *ddev = pci_get_drvdata(pdev);
  120. if (!ddev || !ddev->dev_private)
  121. return -ENODEV;
  122. return ast_drm_freeze(ddev);
  123. }
  124. static int ast_pm_thaw(struct device *dev)
  125. {
  126. struct pci_dev *pdev = to_pci_dev(dev);
  127. struct drm_device *ddev = pci_get_drvdata(pdev);
  128. return ast_drm_thaw(ddev);
  129. }
  130. static int ast_pm_poweroff(struct device *dev)
  131. {
  132. struct pci_dev *pdev = to_pci_dev(dev);
  133. struct drm_device *ddev = pci_get_drvdata(pdev);
  134. return ast_drm_freeze(ddev);
  135. }
  136. static const struct dev_pm_ops ast_pm_ops = {
  137. .suspend = ast_pm_suspend,
  138. .resume = ast_pm_resume,
  139. .freeze = ast_pm_freeze,
  140. .thaw = ast_pm_thaw,
  141. .poweroff = ast_pm_poweroff,
  142. .restore = ast_pm_resume,
  143. };
  144. static struct pci_driver ast_pci_driver = {
  145. .name = DRIVER_NAME,
  146. .id_table = pciidlist,
  147. .probe = ast_pci_probe,
  148. .remove = ast_pci_remove,
  149. .driver.pm = &ast_pm_ops,
  150. };
  151. static const struct file_operations ast_fops = {
  152. .owner = THIS_MODULE,
  153. .open = drm_open,
  154. .release = drm_release,
  155. .unlocked_ioctl = drm_ioctl,
  156. .mmap = ast_mmap,
  157. .poll = drm_poll,
  158. .fasync = drm_fasync,
  159. .read = drm_read,
  160. };
  161. static struct drm_driver driver = {
  162. .driver_features = DRIVER_USE_MTRR | DRIVER_MODESET | DRIVER_GEM,
  163. .dev_priv_size = 0,
  164. .load = ast_driver_load,
  165. .unload = ast_driver_unload,
  166. .fops = &ast_fops,
  167. .name = DRIVER_NAME,
  168. .desc = DRIVER_DESC,
  169. .date = DRIVER_DATE,
  170. .major = DRIVER_MAJOR,
  171. .minor = DRIVER_MINOR,
  172. .patchlevel = DRIVER_PATCHLEVEL,
  173. .gem_init_object = ast_gem_init_object,
  174. .gem_free_object = ast_gem_free_object,
  175. .dumb_create = ast_dumb_create,
  176. .dumb_map_offset = ast_dumb_mmap_offset,
  177. .dumb_destroy = ast_dumb_destroy,
  178. };
  179. static int __init ast_init(void)
  180. {
  181. #ifdef CONFIG_VGA_CONSOLE
  182. if (vgacon_text_force() && ast_modeset == -1)
  183. return -EINVAL;
  184. #endif
  185. if (ast_modeset == 0)
  186. return -EINVAL;
  187. return drm_pci_init(&driver, &ast_pci_driver);
  188. }
  189. static void __exit ast_exit(void)
  190. {
  191. drm_pci_exit(&driver, &ast_pci_driver);
  192. }
  193. module_init(ast_init);
  194. module_exit(ast_exit);
  195. MODULE_AUTHOR(DRIVER_AUTHOR);
  196. MODULE_DESCRIPTION(DRIVER_DESC);
  197. MODULE_LICENSE("GPL and additional rights");