nv04_display.c 5.6 KB

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