nv04_display.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <drm/drmP.h>
  25. #include <drm/drm_crtc_helper.h>
  26. #include "nouveau_drm.h"
  27. #include "nouveau_reg.h"
  28. #include "nouveau_hw.h"
  29. #include "nouveau_encoder.h"
  30. #include "nouveau_connector.h"
  31. int
  32. nv04_display_early_init(struct drm_device *dev)
  33. {
  34. /* ensure vblank interrupts are off, they can't be enabled until
  35. * drm_vblank has been initialised
  36. */
  37. NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
  38. if (nv_two_heads(dev))
  39. NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
  40. return 0;
  41. }
  42. void
  43. nv04_display_late_takedown(struct drm_device *dev)
  44. {
  45. }
  46. int
  47. nv04_display_create(struct drm_device *dev)
  48. {
  49. struct nouveau_drm *drm = nouveau_drm(dev);
  50. struct dcb_table *dcb = &drm->vbios.dcb;
  51. struct drm_connector *connector, *ct;
  52. struct drm_encoder *encoder;
  53. struct drm_crtc *crtc;
  54. struct nv04_display *disp;
  55. int i, ret;
  56. NV_DEBUG(drm, "\n");
  57. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  58. if (!disp)
  59. return -ENOMEM;
  60. nouveau_display(dev)->priv = disp;
  61. nouveau_display(dev)->dtor = nv04_display_destroy;
  62. nouveau_display(dev)->init = nv04_display_init;
  63. nouveau_display(dev)->fini = nv04_display_fini;
  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(drm, "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(drm, "%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. return 0;
  110. }
  111. void
  112. nv04_display_destroy(struct drm_device *dev)
  113. {
  114. struct nouveau_drm *drm = nouveau_drm(dev);
  115. struct nv04_display *disp = nv04_display(dev);
  116. struct drm_encoder *encoder;
  117. struct drm_crtc *crtc;
  118. NV_DEBUG(drm, "\n");
  119. /* Turn every CRTC off. */
  120. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  121. struct drm_mode_set modeset = {
  122. .crtc = crtc,
  123. };
  124. crtc->funcs->set_config(&modeset);
  125. }
  126. /* Restore state */
  127. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  128. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  129. func->restore(encoder);
  130. }
  131. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  132. crtc->funcs->restore(crtc);
  133. nouveau_hw_save_vga_fonts(dev, 0);
  134. nouveau_display(dev)->priv = NULL;
  135. kfree(disp);
  136. }
  137. int
  138. nv04_display_init(struct drm_device *dev)
  139. {
  140. struct drm_encoder *encoder;
  141. struct drm_crtc *crtc;
  142. /* meh.. modeset apparently doesn't setup all the regs and depends
  143. * on pre-existing state, for now load the state of the card *before*
  144. * nouveau was loaded, and then do a modeset.
  145. *
  146. * best thing to do probably is to make save/restore routines not
  147. * save/restore "pre-load" state, but more general so we can save
  148. * on suspend too.
  149. */
  150. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  151. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  152. func->restore(encoder);
  153. }
  154. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  155. crtc->funcs->restore(crtc);
  156. return 0;
  157. }
  158. void
  159. nv04_display_fini(struct drm_device *dev)
  160. {
  161. /* disable vblank interrupts */
  162. NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
  163. if (nv_two_heads(dev))
  164. NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
  165. }