blob: d8540a64a8d3469baaf100402e4a1b84d6dc4d57 [file] [log] [blame]
Ben Skeggs25575b42011-10-05 11:05:07 +10001/*
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"
Ben Skeggs52c7bcd2011-10-05 14:52:02 +100029#include "nouveau_crtc.h"
Ben Skeggs25575b42011-10-05 11:05:07 +100030
31static bool
32hdmi_sor(struct drm_encoder *encoder)
33{
34 struct drm_nouveau_private *dev_priv = encoder->dev->dev_private;
35 if (dev_priv->chipset < 0xa3)
36 return false;
37 return true;
38}
39
Ben Skeggs52c7bcd2011-10-05 14:52:02 +100040static inline u32
41hdmi_base(struct drm_encoder *encoder)
42{
43 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
44 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
45 if (!hdmi_sor(encoder))
46 return 0x616500 + (nv_crtc->index * 0x800);
47 return 0x61c500 + (nv_encoder->or * 0x800);
48}
49
50static void
51hdmi_wr32(struct drm_encoder *encoder, u32 reg, u32 val)
52{
53 nv_wr32(encoder->dev, hdmi_base(encoder) + reg, val);
54}
55
56static u32
57hdmi_rd32(struct drm_encoder *encoder, u32 reg)
58{
59 return nv_rd32(encoder->dev, hdmi_base(encoder) + reg);
60}
61
62static u32
63hdmi_mask(struct drm_encoder *encoder, u32 reg, u32 mask, u32 val)
64{
65 u32 tmp = hdmi_rd32(encoder, reg);
66 hdmi_wr32(encoder, reg, (tmp & ~mask) | val);
67 return tmp;
68}
69
Ben Skeggs25575b42011-10-05 11:05:07 +100070static void
71nouveau_audio_disconnect(struct drm_encoder *encoder)
72{
73 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
74 struct drm_device *dev = encoder->dev;
Ben Skeggs52c7bcd2011-10-05 14:52:02 +100075 u32 or = nv_encoder->or * 0x800;
Ben Skeggs25575b42011-10-05 11:05:07 +100076
77 if (hdmi_sor(encoder)) {
78 nv_mask(dev, 0x61c448 + or, 0x00000003, 0x00000000);
79 }
80}
81
82static void
83nouveau_audio_mode_set(struct drm_encoder *encoder,
84 struct drm_display_mode *mode)
85{
86 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
87 struct nouveau_connector *nv_connector;
88 struct drm_device *dev = encoder->dev;
89 u32 or = nv_encoder->or * 0x800;
90 int i;
91
92 nv_connector = nouveau_encoder_connector_get(nv_encoder);
93 if (!drm_detect_monitor_audio(nv_connector->edid)) {
94 nouveau_audio_disconnect(encoder);
95 return;
96 }
97
98 if (hdmi_sor(encoder)) {
99 nv_mask(dev, 0x61c448 + or, 0x00000001, 0x00000001);
100
101 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
102 if (nv_connector->base.eld[0]) {
103 u8 *eld = nv_connector->base.eld;
104 for (i = 0; i < eld[2] * 4; i++)
105 nv_wr32(dev, 0x61c440 + or, (i << 8) | eld[i]);
106 for (i = eld[2] * 4; i < 0x60; i++)
107 nv_wr32(dev, 0x61c440 + or, (i << 8) | 0x00);
108 nv_mask(dev, 0x61c448 + or, 0x00000002, 0x00000002);
109 }
110 }
111}
112
113static void
114nouveau_hdmi_disconnect(struct drm_encoder *encoder)
115{
116 nouveau_audio_disconnect(encoder);
117}
118
119void
120nouveau_hdmi_mode_set(struct drm_encoder *encoder,
121 struct drm_display_mode *mode)
122{
123 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
124 struct nouveau_connector *nv_connector;
125
126 nv_connector = nouveau_encoder_connector_get(nv_encoder);
127 if (!mode || !nv_connector || !nv_connector->edid ||
128 !drm_detect_hdmi_monitor(nv_connector->edid)) {
129 nouveau_hdmi_disconnect(encoder);
130 return;
131 }
132
133 nouveau_audio_mode_set(encoder, mode);
134}