nv04_display.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /*
  2. * Copyright 2009 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 "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Author: Ben Skeggs
  23. */
  24. #include "drmP.h"
  25. #include "drm.h"
  26. #include "drm_crtc_helper.h"
  27. #include "nouveau_drv.h"
  28. #include "nouveau_fb.h"
  29. #include "nouveau_hw.h"
  30. #include "nouveau_encoder.h"
  31. #include "nouveau_connector.h"
  32. static void nv04_vblank_crtc0_isr(struct drm_device *);
  33. static void nv04_vblank_crtc1_isr(struct drm_device *);
  34. int
  35. nv04_display_early_init(struct drm_device *dev)
  36. {
  37. /* ensure vblank interrupts are off, they can't be enabled until
  38. * drm_vblank has been initialised
  39. */
  40. NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
  41. if (nv_two_heads(dev))
  42. NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
  43. return 0;
  44. }
  45. void
  46. nv04_display_late_takedown(struct drm_device *dev)
  47. {
  48. }
  49. int
  50. nv04_display_create(struct drm_device *dev)
  51. {
  52. struct drm_nouveau_private *dev_priv = dev->dev_private;
  53. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  54. struct drm_connector *connector, *ct;
  55. struct drm_encoder *encoder;
  56. struct drm_crtc *crtc;
  57. struct nv04_display *disp;
  58. int i, ret;
  59. NV_DEBUG_KMS(dev, "\n");
  60. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  61. dev_priv->engine.display.priv = disp;
  62. if (!disp)
  63. return -ENOMEM;
  64. nouveau_hw_save_vga_fonts(dev, 1);
  65. nv04_crtc_create(dev, 0);
  66. if (nv_two_heads(dev))
  67. nv04_crtc_create(dev, 1);
  68. for (i = 0; i < dcb->entries; i++) {
  69. struct dcb_output *dcbent = &dcb->entry[i];
  70. connector = nouveau_connector_create(dev, dcbent->connector);
  71. if (IS_ERR(connector))
  72. continue;
  73. switch (dcbent->type) {
  74. case DCB_OUTPUT_ANALOG:
  75. ret = nv04_dac_create(connector, dcbent);
  76. break;
  77. case DCB_OUTPUT_LVDS:
  78. case DCB_OUTPUT_TMDS:
  79. ret = nv04_dfp_create(connector, dcbent);
  80. break;
  81. case DCB_OUTPUT_TV:
  82. if (dcbent->location == DCB_LOC_ON_CHIP)
  83. ret = nv17_tv_create(connector, dcbent);
  84. else
  85. ret = nv04_tv_create(connector, dcbent);
  86. break;
  87. default:
  88. NV_WARN(dev, "DCB type %d not known\n", dcbent->type);
  89. continue;
  90. }
  91. if (ret)
  92. continue;
  93. }
  94. list_for_each_entry_safe(connector, ct,
  95. &dev->mode_config.connector_list, head) {
  96. if (!connector->encoder_ids[0]) {
  97. NV_WARN(dev, "%s has no encoders, removing\n",
  98. drm_get_connector_name(connector));
  99. connector->funcs->destroy(connector);
  100. }
  101. }
  102. /* Save previous state */
  103. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  104. crtc->funcs->save(crtc);
  105. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  106. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  107. func->save(encoder);
  108. }
  109. nouveau_irq_register(dev, 24, nv04_vblank_crtc0_isr);
  110. nouveau_irq_register(dev, 25, nv04_vblank_crtc1_isr);
  111. return 0;
  112. }
  113. void
  114. nv04_display_destroy(struct drm_device *dev)
  115. {
  116. struct drm_nouveau_private *dev_priv = dev->dev_private;
  117. struct nv04_display *disp = nv04_display(dev);
  118. struct drm_encoder *encoder;
  119. struct drm_crtc *crtc;
  120. NV_DEBUG_KMS(dev, "\n");
  121. nouveau_irq_unregister(dev, 24);
  122. nouveau_irq_unregister(dev, 25);
  123. /* Turn every CRTC off. */
  124. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  125. struct drm_mode_set modeset = {
  126. .crtc = crtc,
  127. };
  128. crtc->funcs->set_config(&modeset);
  129. }
  130. /* Restore state */
  131. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  132. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  133. func->restore(encoder);
  134. }
  135. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  136. crtc->funcs->restore(crtc);
  137. nouveau_hw_save_vga_fonts(dev, 0);
  138. dev_priv->engine.display.priv = NULL;
  139. kfree(disp);
  140. }
  141. int
  142. nv04_display_init(struct drm_device *dev)
  143. {
  144. struct drm_encoder *encoder;
  145. struct drm_crtc *crtc;
  146. /* meh.. modeset apparently doesn't setup all the regs and depends
  147. * on pre-existing state, for now load the state of the card *before*
  148. * nouveau was loaded, and then do a modeset.
  149. *
  150. * best thing to do probably is to make save/restore routines not
  151. * save/restore "pre-load" state, but more general so we can save
  152. * on suspend too.
  153. */
  154. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  155. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  156. func->restore(encoder);
  157. }
  158. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  159. crtc->funcs->restore(crtc);
  160. return 0;
  161. }
  162. void
  163. nv04_display_fini(struct drm_device *dev)
  164. {
  165. /* disable vblank interrupts */
  166. NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
  167. if (nv_two_heads(dev))
  168. NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
  169. }
  170. static void
  171. nv04_vblank_crtc0_isr(struct drm_device *dev)
  172. {
  173. nv_wr32(dev, NV_CRTC0_INTSTAT, NV_CRTC_INTR_VBLANK);
  174. drm_handle_vblank(dev, 0);
  175. }
  176. static void
  177. nv04_vblank_crtc1_isr(struct drm_device *dev)
  178. {
  179. nv_wr32(dev, NV_CRTC1_INTSTAT, NV_CRTC_INTR_VBLANK);
  180. drm_handle_vblank(dev, 1);
  181. }