nouveau_hdmi.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 "drmP.h"
  25. #include "nouveau_drv.h"
  26. #include "nouveau_connector.h"
  27. #include "nouveau_encoder.h"
  28. static bool
  29. hdmi_sor(struct drm_encoder *encoder)
  30. {
  31. struct drm_nouveau_private *dev_priv = encoder->dev->dev_private;
  32. if (dev_priv->chipset < 0xa3)
  33. return false;
  34. return true;
  35. }
  36. static void
  37. nouveau_audio_disconnect(struct drm_encoder *encoder)
  38. {
  39. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  40. struct drm_device *dev = encoder->dev;
  41. int or = nv_encoder->or * 0x800;
  42. if (hdmi_sor(encoder)) {
  43. nv_mask(dev, 0x61c448 + or, 0x00000003, 0x00000000);
  44. }
  45. }
  46. static void
  47. nouveau_audio_mode_set(struct drm_encoder *encoder,
  48. struct drm_display_mode *mode)
  49. {
  50. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  51. struct nouveau_connector *nv_connector;
  52. struct drm_device *dev = encoder->dev;
  53. u32 or = nv_encoder->or * 0x800;
  54. int i;
  55. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  56. if (!drm_detect_monitor_audio(nv_connector->edid)) {
  57. nouveau_audio_disconnect(encoder);
  58. return;
  59. }
  60. if (hdmi_sor(encoder)) {
  61. nv_mask(dev, 0x61c448 + or, 0x00000001, 0x00000001);
  62. drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
  63. if (nv_connector->base.eld[0]) {
  64. u8 *eld = nv_connector->base.eld;
  65. for (i = 0; i < eld[2] * 4; i++)
  66. nv_wr32(dev, 0x61c440 + or, (i << 8) | eld[i]);
  67. for (i = eld[2] * 4; i < 0x60; i++)
  68. nv_wr32(dev, 0x61c440 + or, (i << 8) | 0x00);
  69. nv_mask(dev, 0x61c448 + or, 0x00000002, 0x00000002);
  70. }
  71. }
  72. }
  73. static void
  74. nouveau_hdmi_disconnect(struct drm_encoder *encoder)
  75. {
  76. nouveau_audio_disconnect(encoder);
  77. }
  78. void
  79. nouveau_hdmi_mode_set(struct drm_encoder *encoder,
  80. struct drm_display_mode *mode)
  81. {
  82. struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
  83. struct nouveau_connector *nv_connector;
  84. nv_connector = nouveau_encoder_connector_get(nv_encoder);
  85. if (!mode || !nv_connector || !nv_connector->edid ||
  86. !drm_detect_hdmi_monitor(nv_connector->edid)) {
  87. nouveau_hdmi_disconnect(encoder);
  88. return;
  89. }
  90. nouveau_audio_mode_set(encoder, mode);
  91. }