nouveau_hdmi.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /*
  2. * Copyright 2011 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. * Authors: Ben Skeggs
  23. */
  24. #include <drm/drmP.h>
  25. #include "nouveau_drm.h"
  26. #include "nouveau_connector.h"
  27. #include "nouveau_encoder.h"
  28. #include "nouveau_crtc.h"
  29. #include <core/class.h>
  30. #include "nv50_display.h"
  31. static bool
  32. hdmi_sor(struct drm_encoder *encoder)
  33. {
  34. struct nouveau_drm *drm = nouveau_drm(encoder->dev);
  35. if (nv_device(drm->device)->chipset < 0xa3 ||
  36. nv_device(drm->device)->chipset == 0xaa ||
  37. nv_device(drm->device)->chipset == 0xac)
  38. return false;
  39. return true;
  40. }
  41. static void
  42. nouveau_audio_disconnect(struct drm_encoder *encoder)
  43. {
  44. struct nv50_display *priv = nv50_display(encoder->dev);
  45. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  46. u32 or = nv_encoder->or;
  47. if (hdmi_sor(encoder))
  48. nv_exec(priv->core, NVA3_DISP_SOR_HDA_ELD + or, NULL, 0);
  49. }
  50. static void
  51. nouveau_audio_mode_set(struct drm_encoder *encoder,
  52. struct drm_display_mode *mode)
  53. {
  54. struct nv50_display *priv = nv50_display(encoder->dev);
  55. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  56. struct nouveau_connector *nv_connector;
  57. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  58. if (!drm_detect_monitor_audio(nv_connector->edid)) {
  59. nouveau_audio_disconnect(encoder);
  60. return;
  61. }
  62. if (hdmi_sor(encoder)) {
  63. drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
  64. nv_exec(priv->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or,
  65. nv_connector->base.eld,
  66. nv_connector->base.eld[2] * 4);
  67. }
  68. }
  69. static void
  70. nouveau_hdmi_disconnect(struct drm_encoder *encoder)
  71. {
  72. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  73. struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
  74. struct nv50_display *priv = nv50_display(encoder->dev);
  75. const u32 moff = (nv_crtc->index << 3) | nv_encoder->or;
  76. nouveau_audio_disconnect(encoder);
  77. nv_call(priv->core, NV84_DISP_SOR_HDMI_PWR + moff, 0x00000000);
  78. }
  79. void
  80. nouveau_hdmi_mode_set(struct drm_encoder *encoder,
  81. struct drm_display_mode *mode)
  82. {
  83. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  84. struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
  85. struct nv50_display *priv = nv50_display(encoder->dev);
  86. const u32 moff = (nv_crtc->index << 3) | nv_encoder->or;
  87. struct nouveau_connector *nv_connector;
  88. u32 max_ac_packet, rekey;
  89. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  90. if (!mode || !nv_connector || !nv_connector->edid ||
  91. !drm_detect_hdmi_monitor(nv_connector->edid)) {
  92. nouveau_hdmi_disconnect(encoder);
  93. return;
  94. }
  95. /* value matches nvidia binary driver, and tegra constant */
  96. rekey = 56;
  97. max_ac_packet = mode->htotal - mode->hdisplay;
  98. max_ac_packet -= rekey;
  99. max_ac_packet -= 18; /* constant from tegra */
  100. max_ac_packet /= 32;
  101. nv_call(priv->core, NV84_DISP_SOR_HDMI_PWR + moff,
  102. NV84_DISP_SOR_HDMI_PWR_STATE_ON |
  103. (max_ac_packet << 16) | rekey);
  104. nouveau_audio_mode_set(encoder, mode);
  105. }