nv04_display.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  57. if (!disp)
  58. return -ENOMEM;
  59. nouveau_display(dev)->priv = disp;
  60. nouveau_display(dev)->dtor = nv04_display_destroy;
  61. nouveau_display(dev)->init = nv04_display_init;
  62. nouveau_display(dev)->fini = nv04_display_fini;
  63. nouveau_hw_save_vga_fonts(dev, 1);
  64. nv04_crtc_create(dev, 0);
  65. if (nv_two_heads(dev))
  66. nv04_crtc_create(dev, 1);
  67. for (i = 0; i < dcb->entries; i++) {
  68. struct dcb_output *dcbent = &dcb->entry[i];
  69. connector = nouveau_connector_create(dev, dcbent->connector);
  70. if (IS_ERR(connector))
  71. continue;
  72. switch (dcbent->type) {
  73. case DCB_OUTPUT_ANALOG:
  74. ret = nv04_dac_create(connector, dcbent);
  75. break;
  76. case DCB_OUTPUT_LVDS:
  77. case DCB_OUTPUT_TMDS:
  78. ret = nv04_dfp_create(connector, dcbent);
  79. break;
  80. case DCB_OUTPUT_TV:
  81. if (dcbent->location == DCB_LOC_ON_CHIP)
  82. ret = nv17_tv_create(connector, dcbent);
  83. else
  84. ret = nv04_tv_create(connector, dcbent);
  85. break;
  86. default:
  87. NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
  88. continue;
  89. }
  90. if (ret)
  91. continue;
  92. }
  93. list_for_each_entry_safe(connector, ct,
  94. &dev->mode_config.connector_list, head) {
  95. if (!connector->encoder_ids[0]) {
  96. NV_WARN(drm, "%s has no encoders, removing\n",
  97. drm_get_connector_name(connector));
  98. connector->funcs->destroy(connector);
  99. }
  100. }
  101. /* Save previous state */
  102. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  103. crtc->funcs->save(crtc);
  104. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  105. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  106. func->save(encoder);
  107. }
  108. return 0;
  109. }
  110. void
  111. nv04_display_destroy(struct drm_device *dev)
  112. {
  113. struct nv04_display *disp = nv04_display(dev);
  114. struct drm_encoder *encoder;
  115. struct drm_crtc *crtc;
  116. /* Turn every CRTC off. */
  117. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  118. struct drm_mode_set modeset = {
  119. .crtc = crtc,
  120. };
  121. crtc->funcs->set_config(&modeset);
  122. }
  123. /* Restore state */
  124. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  125. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  126. func->restore(encoder);
  127. }
  128. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  129. crtc->funcs->restore(crtc);
  130. nouveau_hw_save_vga_fonts(dev, 0);
  131. nouveau_display(dev)->priv = NULL;
  132. kfree(disp);
  133. }
  134. int
  135. nv04_display_init(struct drm_device *dev)
  136. {
  137. struct drm_encoder *encoder;
  138. struct drm_crtc *crtc;
  139. /* meh.. modeset apparently doesn't setup all the regs and depends
  140. * on pre-existing state, for now load the state of the card *before*
  141. * nouveau was loaded, and then do a modeset.
  142. *
  143. * best thing to do probably is to make save/restore routines not
  144. * save/restore "pre-load" state, but more general so we can save
  145. * on suspend too.
  146. */
  147. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  148. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  149. func->restore(encoder);
  150. }
  151. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  152. crtc->funcs->restore(crtc);
  153. return 0;
  154. }
  155. void
  156. nv04_display_fini(struct drm_device *dev)
  157. {
  158. /* disable vblank interrupts */
  159. NVWriteCRTC(dev, 0, NV_PCRTC_INTR_EN_0, 0);
  160. if (nv_two_heads(dev))
  161. NVWriteCRTC(dev, 1, NV_PCRTC_INTR_EN_0, 0);
  162. }