disp.c 5.1 KB

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