nv04_display.c 6.7 KB

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