nv04_display.c 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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_KMS(dev, "\n");
  88. if (nv_two_heads(dev))
  89. nv04_display_store_initial_head_owner(dev);
  90. nouveau_hw_save_vga_fonts(dev, 1);
  91. drm_mode_config_init(dev);
  92. drm_mode_create_scaling_mode_property(dev);
  93. drm_mode_create_dithering_property(dev);
  94. dev->mode_config.funcs = (void *)&nouveau_mode_config_funcs;
  95. dev->mode_config.min_width = 0;
  96. dev->mode_config.min_height = 0;
  97. switch (dev_priv->card_type) {
  98. case NV_04:
  99. dev->mode_config.max_width = 2048;
  100. dev->mode_config.max_height = 2048;
  101. break;
  102. default:
  103. dev->mode_config.max_width = 4096;
  104. dev->mode_config.max_height = 4096;
  105. break;
  106. }
  107. dev->mode_config.fb_base = dev_priv->fb_phys;
  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. switch (dcbent->type) {
  114. case OUTPUT_ANALOG:
  115. ret = nv04_dac_create(dev, dcbent);
  116. break;
  117. case OUTPUT_LVDS:
  118. case OUTPUT_TMDS:
  119. ret = nv04_dfp_create(dev, dcbent);
  120. break;
  121. case OUTPUT_TV:
  122. if (dcbent->location == DCB_LOC_ON_CHIP)
  123. ret = nv17_tv_create(dev, dcbent);
  124. else
  125. ret = nv04_tv_create(dev, dcbent);
  126. break;
  127. default:
  128. NV_WARN(dev, "DCB type %d not known\n", dcbent->type);
  129. continue;
  130. }
  131. if (ret)
  132. continue;
  133. connector[dcbent->connector] |= (1 << dcbent->type);
  134. }
  135. for (i = 0; i < dcb->entries; i++) {
  136. struct dcb_entry *dcbent = &dcb->entry[i];
  137. uint16_t encoders;
  138. int type;
  139. encoders = connector[dcbent->connector];
  140. if (!(encoders & (1 << dcbent->type)))
  141. continue;
  142. connector[dcbent->connector] = 0;
  143. switch (dcbent->type) {
  144. case OUTPUT_ANALOG:
  145. if (!MULTIPLE_ENCODERS(encoders))
  146. type = DRM_MODE_CONNECTOR_VGA;
  147. else
  148. type = DRM_MODE_CONNECTOR_DVII;
  149. break;
  150. case OUTPUT_TMDS:
  151. if (!MULTIPLE_ENCODERS(encoders))
  152. type = DRM_MODE_CONNECTOR_DVID;
  153. else
  154. type = DRM_MODE_CONNECTOR_DVII;
  155. break;
  156. case OUTPUT_LVDS:
  157. type = DRM_MODE_CONNECTOR_LVDS;
  158. #if 0
  159. /* don't create i2c adapter when lvds ddc not allowed */
  160. if (dcbent->lvdsconf.use_straps_for_mode ||
  161. dev_priv->vbios->fp_no_ddc)
  162. i2c_index = 0xf;
  163. #endif
  164. break;
  165. case OUTPUT_TV:
  166. type = DRM_MODE_CONNECTOR_TV;
  167. break;
  168. default:
  169. type = DRM_MODE_CONNECTOR_Unknown;
  170. continue;
  171. }
  172. nouveau_connector_create(dev, dcbent->connector, type);
  173. }
  174. /* Save previous state */
  175. NVLockVgaCrtcs(dev, false);
  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_KMS(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. drm_mode_config_cleanup(dev);
  206. nouveau_hw_save_vga_fonts(dev, 0);
  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. }