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 <core/object.h>
  25. #include <core/class.h>
  26. #include <drm/drmP.h>
  27. #include <drm/drm_crtc_helper.h>
  28. #include "nouveau_drm.h"
  29. #include "nouveau_reg.h"
  30. #include "hw.h"
  31. #include "nouveau_encoder.h"
  32. #include "nouveau_connector.h"
  33. #include <subdev/i2c.h>
  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 nouveau_drm *drm = nouveau_drm(dev);
  53. struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
  54. struct dcb_table *dcb = &drm->vbios.dcb;
  55. struct drm_connector *connector, *ct;
  56. struct drm_encoder *encoder;
  57. struct drm_crtc *crtc;
  58. struct nv04_display *disp;
  59. int i, ret;
  60. disp = kzalloc(sizeof(*disp), GFP_KERNEL);
  61. if (!disp)
  62. return -ENOMEM;
  63. nouveau_display(dev)->priv = disp;
  64. nouveau_display(dev)->dtor = nv04_display_destroy;
  65. nouveau_display(dev)->init = nv04_display_init;
  66. nouveau_display(dev)->fini = nv04_display_fini;
  67. nouveau_hw_save_vga_fonts(dev, 1);
  68. nv04_crtc_create(dev, 0);
  69. if (nv_two_heads(dev))
  70. nv04_crtc_create(dev, 1);
  71. for (i = 0; i < dcb->entries; i++) {
  72. struct dcb_output *dcbent = &dcb->entry[i];
  73. connector = nouveau_connector_create(dev, dcbent->connector);
  74. if (IS_ERR(connector))
  75. continue;
  76. switch (dcbent->type) {
  77. case DCB_OUTPUT_ANALOG:
  78. ret = nv04_dac_create(connector, dcbent);
  79. break;
  80. case DCB_OUTPUT_LVDS:
  81. case DCB_OUTPUT_TMDS:
  82. ret = nv04_dfp_create(connector, dcbent);
  83. break;
  84. case DCB_OUTPUT_TV:
  85. if (dcbent->location == DCB_LOC_ON_CHIP)
  86. ret = nv17_tv_create(connector, dcbent);
  87. else
  88. ret = nv04_tv_create(connector, dcbent);
  89. break;
  90. default:
  91. NV_WARN(drm, "DCB type %d not known\n", dcbent->type);
  92. continue;
  93. }
  94. if (ret)
  95. continue;
  96. }
  97. list_for_each_entry_safe(connector, ct,
  98. &dev->mode_config.connector_list, head) {
  99. if (!connector->encoder_ids[0]) {
  100. NV_WARN(drm, "%s has no encoders, removing\n",
  101. drm_get_connector_name(connector));
  102. connector->funcs->destroy(connector);
  103. }
  104. }
  105. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  106. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  107. nv_encoder->i2c = i2c->find(i2c, nv_encoder->dcb->i2c_index);
  108. }
  109. /* Save previous state */
  110. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  111. crtc->funcs->save(crtc);
  112. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  113. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  114. func->save(encoder);
  115. }
  116. nouveau_overlay_init(dev);
  117. return 0;
  118. }
  119. void
  120. nv04_display_destroy(struct drm_device *dev)
  121. {
  122. struct nv04_display *disp = nv04_display(dev);
  123. struct drm_encoder *encoder;
  124. struct drm_crtc *crtc;
  125. /* Turn every CRTC off. */
  126. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  127. struct drm_mode_set modeset = {
  128. .crtc = crtc,
  129. };
  130. drm_mode_set_config_internal(&modeset);
  131. }
  132. /* Restore state */
  133. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  134. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  135. func->restore(encoder);
  136. }
  137. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  138. crtc->funcs->restore(crtc);
  139. nouveau_hw_save_vga_fonts(dev, 0);
  140. nouveau_display(dev)->priv = NULL;
  141. kfree(disp);
  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. }