nv04_display.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  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. #define MULTIPLE_ENCODERS(e) (e & (e - 1))
  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. goto ownerknown;
  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. NVLockVgaCrtcs(dev, 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. NVLockVgaCrtcs(dev, true);
  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. ownerknown:
  72. NV_INFO(dev, "Initial CRTC_OWNER is %d\n", dev_priv->crtc_owner);
  73. /* we need to ensure the heads are not tied henceforth, or reading any
  74. * 8 bit reg on head B will fail
  75. * setting a single arbitrary head solves that */
  76. NVSetOwner(dev, 0);
  77. }
  78. int
  79. nv04_display_create(struct drm_device *dev)
  80. {
  81. struct drm_nouveau_private *dev_priv = dev->dev_private;
  82. struct parsed_dcb *dcb = dev_priv->vbios->dcb;
  83. struct drm_encoder *encoder;
  84. struct drm_crtc *crtc;
  85. uint16_t connector[16] = { 0 };
  86. int i, ret;
  87. NV_DEBUG(dev, "\n");
  88. if (nv_two_heads(dev))
  89. nv04_display_store_initial_head_owner(dev);
  90. drm_mode_config_init(dev);
  91. drm_mode_create_scaling_mode_property(dev);
  92. drm_mode_create_dithering_property(dev);
  93. dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
  94. dev->mode_config.min_width = 0;
  95. dev->mode_config.min_height = 0;
  96. switch (dev_priv->card_type) {
  97. case NV_04:
  98. dev->mode_config.max_width = 2048;
  99. dev->mode_config.max_height = 2048;
  100. break;
  101. default:
  102. dev->mode_config.max_width = 4096;
  103. dev->mode_config.max_height = 4096;
  104. break;
  105. }
  106. dev->mode_config.fb_base = dev_priv->fb_phys;
  107. nv04_crtc_create(dev, 0);
  108. if (nv_two_heads(dev))
  109. nv04_crtc_create(dev, 1);
  110. for (i = 0; i < dcb->entries; i++) {
  111. struct dcb_entry *dcbent = &dcb->entry[i];
  112. switch (dcbent->type) {
  113. case OUTPUT_ANALOG:
  114. ret = nv04_dac_create(dev, dcbent);
  115. break;
  116. case OUTPUT_LVDS:
  117. case OUTPUT_TMDS:
  118. ret = nv04_dfp_create(dev, dcbent);
  119. break;
  120. case OUTPUT_TV:
  121. if (dcbent->location == DCB_LOC_ON_CHIP)
  122. ret = nv17_tv_create(dev, dcbent);
  123. else
  124. ret = nv04_tv_create(dev, dcbent);
  125. break;
  126. default:
  127. NV_WARN(dev, "DCB type %d not known\n", dcbent->type);
  128. continue;
  129. }
  130. if (ret)
  131. continue;
  132. connector[dcbent->connector] |= (1 << dcbent->type);
  133. }
  134. for (i = 0; i < dcb->entries; i++) {
  135. struct dcb_entry *dcbent = &dcb->entry[i];
  136. uint16_t encoders;
  137. int type;
  138. encoders = connector[dcbent->connector];
  139. if (!(encoders & (1 << dcbent->type)))
  140. continue;
  141. connector[dcbent->connector] = 0;
  142. switch (dcbent->type) {
  143. case OUTPUT_ANALOG:
  144. if (!MULTIPLE_ENCODERS(encoders))
  145. type = DRM_MODE_CONNECTOR_VGA;
  146. else
  147. type = DRM_MODE_CONNECTOR_DVII;
  148. break;
  149. case OUTPUT_TMDS:
  150. if (!MULTIPLE_ENCODERS(encoders))
  151. type = DRM_MODE_CONNECTOR_DVID;
  152. else
  153. type = DRM_MODE_CONNECTOR_DVII;
  154. break;
  155. case OUTPUT_LVDS:
  156. type = DRM_MODE_CONNECTOR_LVDS;
  157. #if 0
  158. /* don't create i2c adapter when lvds ddc not allowed */
  159. if (dcbent->lvdsconf.use_straps_for_mode ||
  160. dev_priv->vbios->fp_no_ddc)
  161. i2c_index = 0xf;
  162. #endif
  163. break;
  164. case OUTPUT_TV:
  165. type = DRM_MODE_CONNECTOR_TV;
  166. break;
  167. default:
  168. type = DRM_MODE_CONNECTOR_Unknown;
  169. continue;
  170. }
  171. nouveau_connector_create(dev, dcbent->connector, type);
  172. }
  173. /* Save previous state */
  174. NVLockVgaCrtcs(dev, false);
  175. nouveau_hw_save_vga_fonts(dev, 1);
  176. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  177. crtc->funcs->save(crtc);
  178. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  179. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  180. func->save(encoder);
  181. }
  182. return 0;
  183. }
  184. void
  185. nv04_display_destroy(struct drm_device *dev)
  186. {
  187. struct drm_encoder *encoder;
  188. struct drm_crtc *crtc;
  189. NV_DEBUG(dev, "\n");
  190. /* Turn every CRTC off. */
  191. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
  192. struct drm_mode_set modeset = {
  193. .crtc = crtc,
  194. };
  195. crtc->funcs->set_config(&modeset);
  196. }
  197. /* Restore state */
  198. NVLockVgaCrtcs(dev, false);
  199. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  200. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  201. func->restore(encoder);
  202. }
  203. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  204. crtc->funcs->restore(crtc);
  205. nouveau_hw_save_vga_fonts(dev, 0);
  206. drm_mode_config_cleanup(dev);
  207. }
  208. void
  209. nv04_display_restore(struct drm_device *dev)
  210. {
  211. struct drm_nouveau_private *dev_priv = dev->dev_private;
  212. struct drm_encoder *encoder;
  213. struct drm_crtc *crtc;
  214. NVLockVgaCrtcs(dev, false);
  215. /* meh.. modeset apparently doesn't setup all the regs and depends
  216. * on pre-existing state, for now load the state of the card *before*
  217. * nouveau was loaded, and then do a modeset.
  218. *
  219. * best thing to do probably is to make save/restore routines not
  220. * save/restore "pre-load" state, but more general so we can save
  221. * on suspend too.
  222. */
  223. list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) {
  224. struct drm_encoder_helper_funcs *func = encoder->helper_private;
  225. func->restore(encoder);
  226. }
  227. list_for_each_entry(crtc, &dev->mode_config.crtc_list, head)
  228. crtc->funcs->restore(crtc);
  229. if (nv_two_heads(dev)) {
  230. NV_INFO(dev, "Restoring CRTC_OWNER to %d.\n",
  231. dev_priv->crtc_owner);
  232. NVSetOwner(dev, dev_priv->crtc_owner);
  233. }
  234. NVLockVgaCrtcs(dev, true);
  235. }