2 * Copyright 2009 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
25 #include <drm/drm_dp_helper.h>
27 #include "nouveau_drv.h"
28 #include "nouveau_connector.h"
29 #include "nouveau_encoder.h"
30 #include "nouveau_crtc.h"
32 #include <nvif/class.h>
33 #include <nvif/cl5070.h>
35 MODULE_PARM_DESC(mst, "Enable DisplayPort multi-stream (default: enabled)");
36 static int nouveau_mst = 1;
37 module_param_named(mst, nouveau_mst, int, 0400);
40 nouveau_dp_has_sink_count(struct drm_connector *connector,
41 struct nouveau_encoder *outp)
43 return drm_dp_read_sink_count_cap(connector, outp->dp.dpcd, &outp->dp.desc);
46 static enum drm_connector_status
47 nouveau_dp_probe_dpcd(struct nouveau_connector *nv_connector,
48 struct nouveau_encoder *outp)
50 struct drm_connector *connector = &nv_connector->base;
51 struct drm_dp_aux *aux = &nv_connector->aux;
52 struct nv50_mstm *mstm = NULL;
53 enum drm_connector_status status = connector_status_disconnected;
55 u8 *dpcd = outp->dp.dpcd;
57 ret = drm_dp_read_dpcd_caps(aux, dpcd);
61 ret = drm_dp_read_desc(aux, &outp->dp.desc, drm_dp_is_branch(dpcd));
68 mstm->can_mst = drm_dp_read_mst_cap(aux, dpcd);
71 if (nouveau_dp_has_sink_count(connector, outp)) {
72 ret = drm_dp_read_sink_count(aux);
76 outp->dp.sink_count = ret;
79 * Dongle connected, but no display. Don't bother reading
80 * downstream port info
82 if (!outp->dp.sink_count)
83 return connector_status_disconnected;
86 ret = drm_dp_read_downstream_info(aux, dpcd,
87 outp->dp.downstream_ports);
91 status = connector_status_connected;
93 if (status != connector_status_connected) {
94 /* Clear any cached info */
95 outp->dp.sink_count = 0;
101 nouveau_dp_detect(struct nouveau_connector *nv_connector,
102 struct nouveau_encoder *nv_encoder)
104 struct drm_device *dev = nv_encoder->base.base.dev;
105 struct nouveau_drm *drm = nouveau_drm(dev);
106 struct drm_connector *connector = &nv_connector->base;
107 struct nv50_mstm *mstm = nv_encoder->dp.mstm;
108 enum drm_connector_status status;
109 u8 *dpcd = nv_encoder->dp.dpcd;
110 int ret = NOUVEAU_DP_NONE;
112 /* If we've already read the DPCD on an eDP device, we don't need to
113 * reread it as it won't change
115 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP &&
116 dpcd[DP_DPCD_REV] != 0)
117 return NOUVEAU_DP_SST;
119 mutex_lock(&nv_encoder->dp.hpd_irq_lock);
121 /* If we're not ready to handle MST state changes yet, just
122 * report the last status of the connector. We'll reprobe it
123 * once we've resumed.
125 if (mstm->suspended) {
127 ret = NOUVEAU_DP_MST;
128 else if (connector->status ==
129 connector_status_connected)
130 ret = NOUVEAU_DP_SST;
136 status = nouveau_dp_probe_dpcd(nv_connector, nv_encoder);
137 if (status == connector_status_disconnected)
140 /* If we're in MST mode, we're done here */
141 if (mstm && mstm->can_mst && mstm->is_mst) {
142 ret = NOUVEAU_DP_MST;
146 nv_encoder->dp.link_bw = 27000 * dpcd[DP_MAX_LINK_RATE];
147 nv_encoder->dp.link_nr =
148 dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;
150 NV_DEBUG(drm, "display: %dx%d dpcd 0x%02x\n",
151 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw,
153 NV_DEBUG(drm, "encoder: %dx%d\n",
154 nv_encoder->dcb->dpconf.link_nr,
155 nv_encoder->dcb->dpconf.link_bw);
157 if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr)
158 nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr;
159 if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw)
160 nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw;
162 NV_DEBUG(drm, "maximum: %dx%d\n",
163 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw);
165 if (mstm && mstm->can_mst) {
166 ret = nv50_mstm_detect(nv_encoder);
168 ret = NOUVEAU_DP_MST;
170 } else if (ret != 0) {
174 ret = NOUVEAU_DP_SST;
177 if (mstm && !mstm->suspended && ret != NOUVEAU_DP_MST)
178 nv50_mstm_remove(mstm);
180 mutex_unlock(&nv_encoder->dp.hpd_irq_lock);
184 void nouveau_dp_irq(struct nouveau_drm *drm,
185 struct nouveau_connector *nv_connector)
187 struct drm_connector *connector = &nv_connector->base;
188 struct nouveau_encoder *outp = find_encoder(connector, DCB_OUTPUT_DP);
189 struct nv50_mstm *mstm;
191 bool send_hpd = false;
196 mstm = outp->dp.mstm;
197 NV_DEBUG(drm, "service %s\n", connector->name);
199 mutex_lock(&outp->dp.hpd_irq_lock);
201 if (mstm && mstm->is_mst) {
202 if (!nv50_mstm_service(drm, nv_connector, mstm))
205 drm_dp_cec_irq(&nv_connector->aux);
207 if (nouveau_dp_has_sink_count(connector, outp)) {
208 ret = drm_dp_read_sink_count(&nv_connector->aux);
209 if (ret != outp->dp.sink_count)
212 outp->dp.sink_count = ret;
216 mutex_unlock(&outp->dp.hpd_irq_lock);
219 nouveau_connector_hpd(connector);
223 * - Use the minimum possible BPC here, once we add support for the max bpc
225 * - Validate against the DP caps advertised by the GPU (we don't check these
229 nv50_dp_mode_valid(struct drm_connector *connector,
230 struct nouveau_encoder *outp,
231 const struct drm_display_mode *mode,
234 const unsigned min_clock = 25000;
235 unsigned max_clock, ds_clock, clock;
236 enum drm_mode_status ret;
238 if (mode->flags & DRM_MODE_FLAG_INTERLACE && !outp->caps.dp_interlace)
239 return MODE_NO_INTERLACE;
241 max_clock = outp->dp.link_nr * outp->dp.link_bw;
242 ds_clock = drm_dp_downstream_max_dotclock(outp->dp.dpcd,
243 outp->dp.downstream_ports);
245 max_clock = min(max_clock, ds_clock);
247 clock = mode->clock * (connector->display_info.bpc * 3) / 10;
248 ret = nouveau_conn_mode_clock_valid(mode, min_clock, max_clock,