disp.c 5.2 KB

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