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