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_dpcd_read(aux, DP_DPCD_REV, dpcd, DP_RECEIVER_CAP_SIZE);
58 if (ret == DP_RECEIVER_CAP_SIZE && dpcd[DP_DPCD_REV]) {
59 ret = drm_dp_read_desc(aux, &outp->dp.desc,
60 drm_dp_is_branch(dpcd));
70 mstm->can_mst = drm_dp_read_mst_cap(aux, dpcd);
73 if (nouveau_dp_has_sink_count(connector, outp)) {
74 ret = drm_dp_read_sink_count(aux);
78 outp->dp.sink_count = ret;
81 * Dongle connected, but no display. Don't bother reading
82 * downstream port info
84 if (!outp->dp.sink_count)
85 return connector_status_disconnected;
88 ret = drm_dp_read_downstream_info(aux, dpcd,
89 outp->dp.downstream_ports);
93 status = connector_status_connected;
95 if (status != connector_status_connected) {
96 /* Clear any cached info */
97 outp->dp.sink_count = 0;
103 nouveau_dp_detect(struct nouveau_connector *nv_connector,
104 struct nouveau_encoder *nv_encoder)
106 struct drm_device *dev = nv_encoder->base.base.dev;
107 struct nouveau_drm *drm = nouveau_drm(dev);
108 struct drm_connector *connector = &nv_connector->base;
109 struct nv50_mstm *mstm = nv_encoder->dp.mstm;
110 enum drm_connector_status status;
111 u8 *dpcd = nv_encoder->dp.dpcd;
112 int ret = NOUVEAU_DP_NONE;
114 /* If we've already read the DPCD on an eDP device, we don't need to
115 * reread it as it won't change
117 if (connector->connector_type == DRM_MODE_CONNECTOR_eDP &&
118 dpcd[DP_DPCD_REV] != 0)
119 return NOUVEAU_DP_SST;
121 mutex_lock(&nv_encoder->dp.hpd_irq_lock);
123 /* If we're not ready to handle MST state changes yet, just
124 * report the last status of the connector. We'll reprobe it
125 * once we've resumed.
127 if (mstm->suspended) {
129 ret = NOUVEAU_DP_MST;
130 else if (connector->status ==
131 connector_status_connected)
132 ret = NOUVEAU_DP_SST;
138 status = nouveau_dp_probe_dpcd(nv_connector, nv_encoder);
139 if (status == connector_status_disconnected)
142 /* If we're in MST mode, we're done here */
143 if (mstm && mstm->can_mst && mstm->is_mst) {
144 ret = NOUVEAU_DP_MST;
148 nv_encoder->dp.link_bw = 27000 * dpcd[DP_MAX_LINK_RATE];
149 nv_encoder->dp.link_nr =
150 dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK;
152 NV_DEBUG(drm, "display: %dx%d dpcd 0x%02x\n",
153 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw,
155 NV_DEBUG(drm, "encoder: %dx%d\n",
156 nv_encoder->dcb->dpconf.link_nr,
157 nv_encoder->dcb->dpconf.link_bw);
159 if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr)
160 nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr;
161 if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw)
162 nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw;
164 NV_DEBUG(drm, "maximum: %dx%d\n",
165 nv_encoder->dp.link_nr, nv_encoder->dp.link_bw);
167 if (mstm && mstm->can_mst) {
168 ret = nv50_mstm_detect(nv_encoder);
170 ret = NOUVEAU_DP_MST;
172 } else if (ret != 0) {
176 ret = NOUVEAU_DP_SST;
179 if (mstm && !mstm->suspended && ret != NOUVEAU_DP_MST)
180 nv50_mstm_remove(mstm);
182 mutex_unlock(&nv_encoder->dp.hpd_irq_lock);
186 void nouveau_dp_irq(struct nouveau_drm *drm,
187 struct nouveau_connector *nv_connector)
189 struct drm_connector *connector = &nv_connector->base;
190 struct nouveau_encoder *outp = find_encoder(connector, DCB_OUTPUT_DP);
191 struct nv50_mstm *mstm;
193 bool send_hpd = false;
198 mstm = outp->dp.mstm;
199 NV_DEBUG(drm, "service %s\n", connector->name);
201 mutex_lock(&outp->dp.hpd_irq_lock);
203 if (mstm && mstm->is_mst) {
204 if (!nv50_mstm_service(drm, nv_connector, mstm))
207 drm_dp_cec_irq(&nv_connector->aux);
209 if (nouveau_dp_has_sink_count(connector, outp)) {
210 ret = drm_dp_read_sink_count(&nv_connector->aux);
211 if (ret != outp->dp.sink_count)
214 outp->dp.sink_count = ret;
218 mutex_unlock(&outp->dp.hpd_irq_lock);
221 nouveau_connector_hpd(connector);
225 * - Use the minimum possible BPC here, once we add support for the max bpc
227 * - Validate against the DP caps advertised by the GPU (we don't check these
231 nv50_dp_mode_valid(struct drm_connector *connector,
232 struct nouveau_encoder *outp,
233 const struct drm_display_mode *mode,
236 const unsigned min_clock = 25000;
237 unsigned max_clock, ds_clock, clock;
238 enum drm_mode_status ret;
240 if (mode->flags & DRM_MODE_FLAG_INTERLACE && !outp->caps.dp_interlace)
241 return MODE_NO_INTERLACE;
243 max_clock = outp->dp.link_nr * outp->dp.link_bw;
244 ds_clock = drm_dp_downstream_max_clock(outp->dp.dpcd,
245 outp->dp.downstream_ports);
247 max_clock = min(max_clock, ds_clock);
249 clock = mode->clock * (connector->display_info.bpc * 3) / 10;
250 ret = nouveau_conn_mode_clock_valid(mode, min_clock, max_clock,