nv04_display.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. /* Make the I2C buses accessible. */
  73. if (!nv_gf4_disp_arch(dev)) {
  74. uint32_t pmc_enable = nv_rd32(dev, NV03_PMC_ENABLE);
  75. if (!(pmc_enable & 1))
  76. nv_wr32(dev, NV03_PMC_ENABLE, pmc_enable | 1);
  77. }
  78. /* Unlock the VGA CRTCs. */
  79. NVLockVgaCrtcs(dev, false);
  80. /* Make sure the CRTCs aren't in slaved mode. */
  81. if (nv_two_heads(dev)) {
  82. nv04_display_store_initial_head_owner(dev);
  83. NVSetOwner(dev, 0);
  84. }
  85. return 0;
  86. }
  87. void
  88. nv04_display_late_takedown(struct drm_device *dev)
  89. {
  90. struct drm_nouveau_private *dev_priv = dev->dev_private;
  91. if (nv_two_heads(dev))
  92. NVSetOwner(dev, dev_priv->crtc_owner);
  93. NVLockVgaCrtcs(dev, true);
  94. }
  95. int
  96. nv04_display_create(struct drm_device *dev)
  97. {
  98. struct drm_nouveau_private *dev_priv = dev->dev_private;
  99. struct dcb_table *dcb = &dev_priv->vbios.dcb;
  100. struct drm_connector *connector, *ct;
  101. struct drm_encoder *encoder;
  102. struct drm_crtc *crtc;
  103. int i, ret;
  104. NV_DEBUG_KMS(dev, "\n");
  105. nouveau_hw_save_vga_fonts(dev, 1);
  106. drm_mode_config_init(dev);
  107. drm_mode_create_scaling_mode_property(dev);
  108. drm_mode_create_dithering_property(dev);
  109. dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
  110. dev->mode_config.min_width = 0;
  111. dev->mode_config.min_height = 0;
  112. switch (dev_priv->card_type) {
  113. case NV_04:
  114. dev->mode_config.max_width = 2048;
  115. dev->mode_config.max_height = 2048;
  116. break;
  117. default:
  118. dev->mode_config.max_width = 4096;
  119. dev->mode_config.max_height = 4096;
  120. break;
  121. }
  122. dev->mode_config.fb_base = dev_priv->fb_phys;
  123. nv04_crtc_create(dev, 0);
  124. if (nv_two_heads(dev))
  125. nv04_crtc_create(dev, 1);
  126. for (i = 0; i < dcb->entries; i++) {
  127. struct dcb_entry *dcbent = &dcb->entry[i];
  128. connector = nouveau_connector_create(dev, dcbent->connector);
  129. if (IS_ERR(connector))
  130. continue;
  131. switch (dcbent->type) {
  132. case OUTPUT_ANALOG:
  133. ret = nv04_dac_create(connector, dcbent);
  134. break;
  135. case OUTPUT_LVDS:
  136. case OUTPUT_TMDS:
  137. ret = nv04_dfp_create(connector, dcbent);
  138. break;
  139. case OUTPUT_TV:
  140. if (dcbent->location == DCB_LOC_ON_CHIP)
  141. ret = nv17_tv_create(connector, dcbent);
  142. else
  143. ret = nv04_tv_create(connector, dcbent);
  144. break;
  145. default:
  146. NV_WARN(dev, "DCB type %d not known\n", dcbent->type);
  147. continue;
  148. }
  149. if (ret)
  150. continue;
  151. }
  152. list_for_each_entry_safe(connector, ct,
  153. &dev->mode_config.connector_list, head) {
  154. if (!connector->encoder_ids[0]) {
  155. NV_WARN(dev, "%s has no encoders, removing\n",
  156. drm_get_connector_name(connector));
  157. connector->funcs->destroy(connector);
  158. }
  159. }
  160. /* Save previous state */
  161. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  162. crtc->funcs->save(crtc);
  163. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  164. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  165. func->save(encoder);
  166. }
  167. return 0;
  168. }
  169. void
  170. nv04_display_destroy(struct drm_device *dev)
  171. {
  172. struct drm_encoder *encoder;
  173. struct drm_crtc *crtc;
  174. NV_DEBUG_KMS(dev, "\n");
  175. /* Turn every CRTC off. */
  176. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  177. struct drm_mode_set modeset = {
  178. .crtc = crtc,
  179. };
  180. crtc->funcs->set_config(&modeset);
  181. }
  182. /* Restore state */
  183. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  184. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  185. func->restore(encoder);
  186. }
  187. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  188. crtc->funcs->restore(crtc);
  189. drm_mode_config_cleanup(dev);
  190. nouveau_hw_save_vga_fonts(dev, 0);
  191. }
  192. int
  193. nv04_display_init(struct drm_device *dev)
  194. {
  195. struct drm_encoder *encoder;
  196. struct drm_crtc *crtc;
  197. /* meh.. modeset apparently doesn't setup all the regs and depends
  198. * on pre-existing state, for now load the state of the card *before*
  199. * nouveau was loaded, and then do a modeset.
  200. *
  201. * best thing to do probably is to make save/restore routines not
  202. * save/restore "pre-load" state, but more general so we can save
  203. * on suspend too.
  204. */
  205. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  206. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  207. func->restore(encoder);
  208. }
  209. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  210. crtc->funcs->restore(crtc);
  211. return 0;
  212. }