nv04_display.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 "drmP.h"
  25. #include "drm.h"
  26. #include "drm_crtc_helper.h"
  27. #include "nouveau_drv.h"
  28. #include "nouveau_fb.h"
  29. #include "nouveau_hw.h"
  30. #include "nouveau_encoder.h"
  31. #include "nouveau_connector.h"
  32. static void
  33. nv04_display_store_initial_head_owner(struct drm_device *dev)
  34. {
  35. struct drm_nouveau_private *dev_priv = dev->dev_private;
  36. if (dev_priv->chipset != 0x11) {
  37. dev_priv->crtc_owner = NVReadVgaCrtc(dev, 0, NV_CIO_CRE_44);
  38. return;
  39. }
  40. /* reading CR44 is broken on nv11, so we attempt to infer it */
  41. if (nvReadMC(dev, NV_PBUS_DEBUG_1) & (1 << 28)) /* heads tied, restore both */
  42. dev_priv->crtc_owner = 0x4;
  43. else {
  44. uint8_t slaved_on_A, slaved_on_B;
  45. bool tvA = false;
  46. bool tvB = false;
  47. slaved_on_B = NVReadVgaCrtc(dev, 1, NV_CIO_CRE_PIXEL_INDEX) &
  48. 0x80;
  49. if (slaved_on_B)
  50. tvB = !(NVReadVgaCrtc(dev, 1, NV_CIO_CRE_LCD__INDEX) &
  51. MASK(NV_CIO_CRE_LCD_LCD_SELECT));
  52. slaved_on_A = NVReadVgaCrtc(dev, 0, NV_CIO_CRE_PIXEL_INDEX) &
  53. 0x80;
  54. if (slaved_on_A)
  55. tvA = !(NVReadVgaCrtc(dev, 0, NV_CIO_CRE_LCD__INDEX) &
  56. MASK(NV_CIO_CRE_LCD_LCD_SELECT));
  57. if (slaved_on_A && !tvA)
  58. dev_priv->crtc_owner = 0x0;
  59. else if (slaved_on_B && !tvB)
  60. dev_priv->crtc_owner = 0x3;
  61. else if (slaved_on_A)
  62. dev_priv->crtc_owner = 0x0;
  63. else if (slaved_on_B)
  64. dev_priv->crtc_owner = 0x3;
  65. else
  66. dev_priv->crtc_owner = 0x0;
  67. }
  68. }
  69. int
  70. nv04_display_early_init(struct drm_device *dev)
  71. {
  72. /* Unlock the VGA CRTCs. */
  73. NVLockVgaCrtcs(dev, false);
  74. /* Make sure the CRTCs aren't in slaved mode. */
  75. if (nv_two_heads(dev)) {
  76. nv04_display_store_initial_head_owner(dev);
  77. NVSetOwner(dev, 0);
  78. }
  79. return 0;
  80. }
  81. void
  82. nv04_display_late_takedown(struct drm_device *dev)
  83. {
  84. struct drm_nouveau_private *dev_priv = dev->dev_private;
  85. if (nv_two_heads(dev))
  86. NVSetOwner(dev, dev_priv->crtc_owner);
  87. NVLockVgaCrtcs(dev, true);
  88. }
  89. int
  90. nv04_display_create(struct drm_device *dev)
  91. {
  92. struct drm_nouveau_private *dev_priv = dev->dev_private;
  93. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  94. struct drm_connector *connector, *ct;
  95. struct drm_encoder *encoder;
  96. struct drm_crtc *crtc;
  97. int i, ret;
  98. NV_DEBUG_KMS(dev, "\n");
  99. nouveau_hw_save_vga_fonts(dev, 1);
  100. drm_mode_config_init(dev);
  101. drm_mode_create_scaling_mode_property(dev);
  102. drm_mode_create_dithering_property(dev);
  103. dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
  104. dev->mode_config.min_width = 0;
  105. dev->mode_config.min_height = 0;
  106. switch (dev_priv->card_type) {
  107. case NV_04:
  108. dev->mode_config.max_width = 2048;
  109. dev->mode_config.max_height = 2048;
  110. break;
  111. default:
  112. dev->mode_config.max_width = 4096;
  113. dev->mode_config.max_height = 4096;
  114. break;
  115. }
  116. dev->mode_config.fb_base = dev_priv->fb_phys;
  117. nv04_crtc_create(dev, 0);
  118. if (nv_two_heads(dev))
  119. nv04_crtc_create(dev, 1);
  120. for (i = 0; i < dcb->entries; i++) {
  121. struct dcb_entry *dcbent = &dcb->entry[i];
  122. connector = nouveau_connector_create(dev, dcbent->connector);
  123. if (IS_ERR(connector))
  124. continue;
  125. switch (dcbent->type) {
  126. case OUTPUT_ANALOG:
  127. ret = nv04_dac_create(connector, dcbent);
  128. break;
  129. case OUTPUT_LVDS:
  130. case OUTPUT_TMDS:
  131. ret = nv04_dfp_create(connector, dcbent);
  132. break;
  133. case OUTPUT_TV:
  134. if (dcbent->location == DCB_LOC_ON_CHIP)
  135. ret = nv17_tv_create(connector, dcbent);
  136. else
  137. ret = nv04_tv_create(connector, dcbent);
  138. break;
  139. default:
  140. NV_WARN(dev, "DCB type %d not known\n", dcbent->type);
  141. continue;
  142. }
  143. if (ret)
  144. continue;
  145. }
  146. list_for_each_entry_safe(connector, ct,
  147. &dev->mode_config.connector_list, head) {
  148. if (!connector->encoder_ids[0]) {
  149. NV_WARN(dev, "%s has no encoders, removing\n",
  150. drm_get_connector_name(connector));
  151. connector->funcs->destroy(connector);
  152. }
  153. }
  154. /* Save previous state */
  155. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  156. crtc->funcs->save(crtc);
  157. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  158. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  159. func->save(encoder);
  160. }
  161. return 0;
  162. }
  163. void
  164. nv04_display_destroy(struct drm_device *dev)
  165. {
  166. struct drm_encoder *encoder;
  167. struct drm_crtc *crtc;
  168. NV_DEBUG_KMS(dev, "\n");
  169. /* Turn every CRTC off. */
  170. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  171. struct drm_mode_set modeset = {
  172. .crtc = crtc,
  173. };
  174. crtc->funcs->set_config(&modeset);
  175. }
  176. /* Restore state */
  177. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  178. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  179. func->restore(encoder);
  180. }
  181. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  182. crtc->funcs->restore(crtc);
  183. drm_mode_config_cleanup(dev);
  184. nouveau_hw_save_vga_fonts(dev, 0);
  185. }
  186. int
  187. nv04_display_init(struct drm_device *dev)
  188. {
  189. struct drm_encoder *encoder;
  190. struct drm_crtc *crtc;
  191. /* meh.. modeset apparently doesn't setup all the regs and depends
  192. * on pre-existing state, for now load the state of the card *before*
  193. * nouveau was loaded, and then do a modeset.
  194. *
  195. * best thing to do probably is to make save/restore routines not
  196. * save/restore "pre-load" state, but more general so we can save
  197. * on suspend too.
  198. */
  199. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  200. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  201. func->restore(encoder);
  202. }
  203. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  204. crtc->funcs->restore(crtc);
  205. return 0;
  206. }