nv04_display.c 7.0 KB

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