nv50_dac.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. /*
  2. * Copyright (C) 2008 Maarten Maathuis.
  3. * All Rights Reserved.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice (including the
  14. * next paragraph) shall be included in all copies or substantial
  15. * portions of the Software.
  16. *
  17. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  20. * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
  21. * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. *
  25. */
  26. #include <drm/drmP.h>
  27. #include <drm/drm_crtc_helper.h>
  28. #define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO)
  29. #include "nouveau_reg.h"
  30. #include "nouveau_drm.h"
  31. #include "nouveau_dma.h"
  32. #include "nouveau_encoder.h"
  33. #include "nouveau_connector.h"
  34. #include "nouveau_crtc.h"
  35. #include "nv50_display.h"
  36. #include <core/class.h>
  37. #include <subdev/timer.h>
  38. static void
  39. nv50_dac_disconnect(struct drm_encoder *encoder)
  40. {
  41. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  42. struct drm_device *dev = encoder->dev;
  43. struct nouveau_drm *drm = nouveau_drm(dev);
  44. struct nouveau_channel *evo = nv50_display(dev)->master;
  45. int ret;
  46. if (!nv_encoder->crtc)
  47. return;
  48. nv50_crtc_blank(nouveau_crtc(nv_encoder->crtc), true);
  49. NV_DEBUG(drm, "Disconnecting DAC %d\n", nv_encoder->or);
  50. ret = RING_SPACE(evo, 4);
  51. if (ret) {
  52. NV_ERROR(drm, "no space while disconnecting DAC\n");
  53. return;
  54. }
  55. BEGIN_NV04(evo, 0, NV50_EVO_DAC(nv_encoder->or, MODE_CTRL), 1);
  56. OUT_RING (evo, 0);
  57. BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1);
  58. OUT_RING (evo, 0);
  59. nv_encoder->crtc = NULL;
  60. }
  61. static enum drm_connector_status
  62. nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
  63. {
  64. struct nv50_display *priv = nv50_display(encoder->dev);
  65. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  66. struct nouveau_drm *drm = nouveau_drm(encoder->dev);
  67. int or = nv_encoder->or, ret;
  68. u32 load;
  69. if (drm->vbios.dactestval)
  70. load = drm->vbios.dactestval;
  71. else
  72. load = 340;
  73. ret = nv_exec(priv->core, NV50_DISP_DAC_LOAD + or, &load, sizeof(load));
  74. if (ret || load != 7)
  75. return connector_status_disconnected;
  76. return connector_status_connected;
  77. }
  78. static void
  79. nv50_dac_dpms(struct drm_encoder *encoder, int mode)
  80. {
  81. struct nv50_display *priv = nv50_display(encoder->dev);
  82. struct nouveau_drm *drm = nouveau_drm(encoder->dev);
  83. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  84. uint32_t val;
  85. int or = nv_encoder->or;
  86. NV_DEBUG(drm, "or %d mode %d\n", or, mode);
  87. if (mode != DRM_MODE_DPMS_ON)
  88. val = NV50_PDISPLAY_DAC_DPMS_CTRL_BLANKED;
  89. else
  90. val = 0;
  91. switch (mode) {
  92. case DRM_MODE_DPMS_STANDBY:
  93. val |= NV50_PDISPLAY_DAC_DPMS_CTRL_HSYNC_OFF;
  94. break;
  95. case DRM_MODE_DPMS_SUSPEND:
  96. val |= NV50_PDISPLAY_DAC_DPMS_CTRL_VSYNC_OFF;
  97. break;
  98. case DRM_MODE_DPMS_OFF:
  99. val |= NV50_PDISPLAY_DAC_DPMS_CTRL_OFF;
  100. val |= NV50_PDISPLAY_DAC_DPMS_CTRL_HSYNC_OFF;
  101. val |= NV50_PDISPLAY_DAC_DPMS_CTRL_VSYNC_OFF;
  102. break;
  103. default:
  104. break;
  105. }
  106. nv_call(priv->core, NV50_DISP_DAC_PWR + or, val);
  107. }
  108. static void
  109. nv50_dac_save(struct drm_encoder *encoder)
  110. {
  111. struct nouveau_drm *drm = nouveau_drm(encoder->dev);
  112. NV_ERROR(drm, "!!\n");
  113. }
  114. static void
  115. nv50_dac_restore(struct drm_encoder *encoder)
  116. {
  117. struct nouveau_drm *drm = nouveau_drm(encoder->dev);
  118. NV_ERROR(drm, "!!\n");
  119. }
  120. static bool
  121. nv50_dac_mode_fixup(struct drm_encoder *encoder,
  122. const struct drm_display_mode *mode,
  123. struct drm_display_mode *adjusted_mode)
  124. {
  125. struct nouveau_drm *drm = nouveau_drm(encoder->dev);
  126. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  127. struct nouveau_connector *connector;
  128. NV_DEBUG(drm, "or %d\n", nv_encoder->or);
  129. connector = nouveau_encoder_connector_get(nv_encoder);
  130. if (!connector) {
  131. NV_ERROR(drm, "Encoder has no connector\n");
  132. return false;
  133. }
  134. if (connector->scaling_mode != DRM_MODE_SCALE_NONE &&
  135. connector->native_mode)
  136. drm_mode_copy(adjusted_mode, connector->native_mode);
  137. return true;
  138. }
  139. static void
  140. nv50_dac_commit(struct drm_encoder *encoder)
  141. {
  142. }
  143. static void
  144. nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
  145. struct drm_display_mode *adjusted_mode)
  146. {
  147. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  148. struct nouveau_drm *drm = nouveau_drm(encoder->dev);
  149. struct drm_device *dev = encoder->dev;
  150. struct nouveau_channel *evo = nv50_display(dev)->master;
  151. struct nouveau_crtc *crtc = nouveau_crtc(encoder->crtc);
  152. uint32_t mode_ctl = 0, mode_ctl2 = 0;
  153. int ret;
  154. NV_DEBUG(drm, "or %d type %d crtc %d\n",
  155. nv_encoder->or, nv_encoder->dcb->type, crtc->index);
  156. nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
  157. if (crtc->index == 1)
  158. mode_ctl |= NV50_EVO_DAC_MODE_CTRL_CRTC1;
  159. else
  160. mode_ctl |= NV50_EVO_DAC_MODE_CTRL_CRTC0;
  161. /* Lacking a working tv-out, this is not a 100% sure. */
  162. if (nv_encoder->dcb->type == DCB_OUTPUT_ANALOG)
  163. mode_ctl |= 0x40;
  164. else
  165. if (nv_encoder->dcb->type == DCB_OUTPUT_TV)
  166. mode_ctl |= 0x100;
  167. if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC)
  168. mode_ctl2 |= NV50_EVO_DAC_MODE_CTRL2_NHSYNC;
  169. if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC)
  170. mode_ctl2 |= NV50_EVO_DAC_MODE_CTRL2_NVSYNC;
  171. ret = RING_SPACE(evo, 3);
  172. if (ret) {
  173. NV_ERROR(drm, "no space while connecting DAC\n");
  174. return;
  175. }
  176. BEGIN_NV04(evo, 0, NV50_EVO_DAC(nv_encoder->or, MODE_CTRL), 2);
  177. OUT_RING(evo, mode_ctl);
  178. OUT_RING(evo, mode_ctl2);
  179. nv_encoder->crtc = encoder->crtc;
  180. }
  181. static struct drm_crtc *
  182. nv50_dac_crtc_get(struct drm_encoder *encoder)
  183. {
  184. return nouveau_encoder(encoder)->crtc;
  185. }
  186. static const struct drm_encoder_helper_funcs nv50_dac_helper_funcs = {
  187. .dpms = nv50_dac_dpms,
  188. .save = nv50_dac_save,
  189. .restore = nv50_dac_restore,
  190. .mode_fixup = nv50_dac_mode_fixup,
  191. .prepare = nv50_dac_disconnect,
  192. .commit = nv50_dac_commit,
  193. .mode_set = nv50_dac_mode_set,
  194. .get_crtc = nv50_dac_crtc_get,
  195. .detect = nv50_dac_detect,
  196. .disable = nv50_dac_disconnect
  197. };
  198. static void
  199. nv50_dac_destroy(struct drm_encoder *encoder)
  200. {
  201. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  202. if (!encoder)
  203. return;
  204. drm_encoder_cleanup(encoder);
  205. kfree(nv_encoder);
  206. }
  207. static const struct drm_encoder_funcs nv50_dac_encoder_funcs = {
  208. .destroy = nv50_dac_destroy,
  209. };
  210. int
  211. nv50_dac_create(struct drm_connector *connector, struct dcb_output *entry)
  212. {
  213. struct nouveau_encoder *nv_encoder;
  214. struct drm_encoder *encoder;
  215. nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
  216. if (!nv_encoder)
  217. return -ENOMEM;
  218. encoder = to_drm_encoder(nv_encoder);
  219. nv_encoder->dcb = entry;
  220. nv_encoder->or = ffs(entry->or) - 1;
  221. drm_encoder_init(connector->dev, encoder, &nv50_dac_encoder_funcs,
  222. DRM_MODE_ENCODER_DAC);
  223. drm_encoder_helper_add(encoder, &nv50_dac_helper_funcs);
  224. encoder->possible_crtcs = entry->heads;
  225. encoder->possible_clones = 0;
  226. drm_mode_connector_attach_encoder(connector, encoder);
  227. return 0;
  228. }