nv04_display.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. drm_mode_config_init(dev);
  109. drm_mode_create_scaling_mode_property(dev);
  110. drm_mode_create_dithering_property(dev);
  111. dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
  112. dev->mode_config.min_width = 0;
  113. dev->mode_config.min_height = 0;
  114. switch (dev_priv->card_type) {
  115. case NV_04:
  116. dev->mode_config.max_width = 2048;
  117. dev->mode_config.max_height = 2048;
  118. break;
  119. default:
  120. dev->mode_config.max_width = 4096;
  121. dev->mode_config.max_height = 4096;
  122. break;
  123. }
  124. dev->mode_config.fb_base = dev_priv->fb_phys;
  125. nv04_crtc_create(dev, 0);
  126. if (nv_two_heads(dev))
  127. nv04_crtc_create(dev, 1);
  128. for (i = 0; i < dcb->entries; i++) {
  129. struct dcb_entry *dcbent = &dcb->entry[i];
  130. connector = nouveau_connector_create(dev, dcbent->connector);
  131. if (IS_ERR(connector))
  132. continue;
  133. switch (dcbent->type) {
  134. case OUTPUT_ANALOG:
  135. ret = nv04_dac_create(connector, dcbent);
  136. break;
  137. case OUTPUT_LVDS:
  138. case OUTPUT_TMDS:
  139. ret = nv04_dfp_create(connector, dcbent);
  140. break;
  141. case OUTPUT_TV:
  142. if (dcbent->location == DCB_LOC_ON_CHIP)
  143. ret = nv17_tv_create(connector, dcbent);
  144. else
  145. ret = nv04_tv_create(connector, dcbent);
  146. break;
  147. default:
  148. NV_WARN(dev, "DCB type %d not known\n", dcbent->type);
  149. continue;
  150. }
  151. if (ret)
  152. continue;
  153. }
  154. list_for_each_entry_safe(connector, ct,
  155. &dev->mode_config.connector_list, head) {
  156. if (!connector->encoder_ids[0]) {
  157. NV_WARN(dev, "%s has no encoders, removing\n",
  158. drm_get_connector_name(connector));
  159. connector->funcs->destroy(connector);
  160. }
  161. }
  162. /* Save previous state */
  163. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  164. crtc->funcs->save(crtc);
  165. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  166. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  167. func->save(encoder);
  168. }
  169. nouveau_irq_register(dev, 24, nv04_vblank_crtc0_isr);
  170. nouveau_irq_register(dev, 25, nv04_vblank_crtc1_isr);
  171. return 0;
  172. }
  173. void
  174. nv04_display_destroy(struct drm_device *dev)
  175. {
  176. struct drm_encoder *encoder;
  177. struct drm_crtc *crtc;
  178. NV_DEBUG_KMS(dev, "\n");
  179. nouveau_irq_unregister(dev, 24);
  180. nouveau_irq_unregister(dev, 25);
  181. /* Turn every CRTC off. */
  182. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  183. struct drm_mode_set modeset = {
  184. .crtc = crtc,
  185. };
  186. crtc->funcs->set_config(&modeset);
  187. }
  188. /* Restore state */
  189. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  190. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  191. func->restore(encoder);
  192. }
  193. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  194. crtc->funcs->restore(crtc);
  195. drm_mode_config_cleanup(dev);
  196. nouveau_hw_save_vga_fonts(dev, 0);
  197. }
  198. int
  199. nv04_display_init(struct drm_device *dev)
  200. {
  201. struct drm_encoder *encoder;
  202. struct drm_crtc *crtc;
  203. /* meh.. modeset apparently doesn't setup all the regs and depends
  204. * on pre-existing state, for now load the state of the card *before*
  205. * nouveau was loaded, and then do a modeset.
  206. *
  207. * best thing to do probably is to make save/restore routines not
  208. * save/restore "pre-load" state, but more general so we can save
  209. * on suspend too.
  210. */
  211. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  212. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  213. func->restore(encoder);
  214. }
  215. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  216. crtc->funcs->restore(crtc);
  217. return 0;
  218. }
  219. static void
  220. nv04_vblank_crtc0_isr(struct drm_device *dev)
  221. {
  222. nv_wr32(dev, NV_CRTC0_INTSTAT, NV_CRTC_INTR_VBLANK);
  223. drm_handle_vblank(dev, 0);
  224. }
  225. static void
  226. nv04_vblank_crtc1_isr(struct drm_device *dev)
  227. {
  228. nv_wr32(dev, NV_CRTC1_INTSTAT, NV_CRTC_INTR_VBLANK);
  229. drm_handle_vblank(dev, 1);
  230. }