nv04_display.c 7.0 KB

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