disp.c 5.5 KB

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