disp.c 5.0 KB

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