Commit | Line | Data |
---|---|---|
6ee73861 BS |
1 | /* |
2 | * Copyright 2009 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 | ||
612a9aab | 25 | #include <drm/drm_dp_helper.h> |
b01f0608 | 26 | |
4dc28134 | 27 | #include "nouveau_drv.h" |
b01f0608 | 28 | #include "nouveau_connector.h" |
6ee73861 | 29 | #include "nouveau_encoder.h" |
27a45987 | 30 | #include "nouveau_crtc.h" |
6ee73861 | 31 | |
52aa30f2 BS |
32 | #include <nvif/class.h> |
33 | #include <nvif/cl5070.h> | |
34 | ||
f479c0ba BS |
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); | |
38 | ||
a0922278 LP |
39 | static enum drm_connector_status |
40 | nouveau_dp_probe_dpcd(struct nouveau_connector *nv_connector, | |
41 | struct nouveau_encoder *outp) | |
42 | { | |
43 | struct drm_dp_aux *aux = &nv_connector->aux; | |
44 | struct nv50_mstm *mstm = NULL; | |
45 | int ret; | |
46 | u8 *dpcd = outp->dp.dpcd; | |
a0922278 LP |
47 | |
48 | ret = drm_dp_dpcd_read(aux, DP_DPCD_REV, dpcd, DP_RECEIVER_CAP_SIZE); | |
49 | if (ret == DP_RECEIVER_CAP_SIZE && dpcd[DP_DPCD_REV]) { | |
50 | ret = drm_dp_read_desc(aux, &outp->dp.desc, | |
51 | drm_dp_is_branch(dpcd)); | |
52 | if (ret < 0) | |
53 | return connector_status_disconnected; | |
54 | } else { | |
55 | return connector_status_disconnected; | |
56 | } | |
57 | ||
8b75e83e | 58 | if (nouveau_mst) { |
a0922278 | 59 | mstm = outp->dp.mstm; |
8b75e83e LP |
60 | if (mstm) |
61 | mstm->can_mst = drm_dp_read_mst_cap(aux, dpcd); | |
a0922278 LP |
62 | } |
63 | ||
409d3813 LP |
64 | ret = drm_dp_read_downstream_info(aux, dpcd, |
65 | outp->dp.downstream_ports); | |
66 | if (ret < 0) | |
67 | return connector_status_disconnected; | |
68 | ||
a0922278 LP |
69 | return connector_status_connected; |
70 | } | |
71 | ||
8777c5c1 | 72 | int |
6ba11932 LP |
73 | nouveau_dp_detect(struct nouveau_connector *nv_connector, |
74 | struct nouveau_encoder *nv_encoder) | |
6ee73861 | 75 | { |
8777c5c1 | 76 | struct drm_device *dev = nv_encoder->base.base.dev; |
77145f1c | 77 | struct nouveau_drm *drm = nouveau_drm(dev); |
a0922278 LP |
78 | struct drm_connector *connector = &nv_connector->base; |
79 | struct nv50_mstm *mstm = nv_encoder->dp.mstm; | |
80 | enum drm_connector_status status; | |
81 | u8 *dpcd = nv_encoder->dp.dpcd; | |
82 | int ret = NOUVEAU_DP_NONE; | |
83 | ||
84 | /* If we've already read the DPCD on an eDP device, we don't need to | |
85 | * reread it as it won't change | |
86 | */ | |
87 | if (connector->connector_type == DRM_MODE_CONNECTOR_eDP && | |
88 | dpcd[DP_DPCD_REV] != 0) | |
89 | return NOUVEAU_DP_SST; | |
6ee73861 | 90 | |
a0922278 LP |
91 | mutex_lock(&nv_encoder->dp.hpd_irq_lock); |
92 | if (mstm) { | |
93 | /* If we're not ready to handle MST state changes yet, just | |
94 | * report the last status of the connector. We'll reprobe it | |
95 | * once we've resumed. | |
96 | */ | |
97 | if (mstm->suspended) { | |
98 | if (mstm->is_mst) | |
99 | ret = NOUVEAU_DP_MST; | |
100 | else if (connector->status == | |
101 | connector_status_connected) | |
102 | ret = NOUVEAU_DP_SST; | |
103 | ||
104 | goto out; | |
105 | } | |
106 | } | |
107 | ||
108 | status = nouveau_dp_probe_dpcd(nv_connector, nv_encoder); | |
109 | if (status == connector_status_disconnected) | |
110 | goto out; | |
111 | ||
112 | /* If we're in MST mode, we're done here */ | |
113 | if (mstm && mstm->can_mst && mstm->is_mst) { | |
114 | ret = NOUVEAU_DP_MST; | |
115 | goto out; | |
116 | } | |
6ee73861 | 117 | |
57940402 LP |
118 | nv_encoder->dp.link_bw = 27000 * dpcd[DP_MAX_LINK_RATE]; |
119 | nv_encoder->dp.link_nr = | |
120 | dpcd[DP_MAX_LANE_COUNT] & DP_MAX_LANE_COUNT_MASK; | |
6ee73861 | 121 | |
77145f1c | 122 | NV_DEBUG(drm, "display: %dx%d dpcd 0x%02x\n", |
57940402 LP |
123 | nv_encoder->dp.link_nr, nv_encoder->dp.link_bw, |
124 | dpcd[DP_DPCD_REV]); | |
77145f1c | 125 | NV_DEBUG(drm, "encoder: %dx%d\n", |
bbcd521e LP |
126 | nv_encoder->dcb->dpconf.link_nr, |
127 | nv_encoder->dcb->dpconf.link_bw); | |
6ee73861 | 128 | |
75a1fccf | 129 | if (nv_encoder->dcb->dpconf.link_nr < nv_encoder->dp.link_nr) |
6ee73861 | 130 | nv_encoder->dp.link_nr = nv_encoder->dcb->dpconf.link_nr; |
75a1fccf BS |
131 | if (nv_encoder->dcb->dpconf.link_bw < nv_encoder->dp.link_bw) |
132 | nv_encoder->dp.link_bw = nv_encoder->dcb->dpconf.link_bw; | |
6ee73861 | 133 | |
77145f1c | 134 | NV_DEBUG(drm, "maximum: %dx%d\n", |
bbcd521e | 135 | nv_encoder->dp.link_nr, nv_encoder->dp.link_bw); |
fe224bb7 | 136 | |
a0922278 LP |
137 | if (mstm && mstm->can_mst) { |
138 | ret = nv50_mstm_detect(nv_encoder); | |
139 | if (ret == 1) { | |
140 | ret = NOUVEAU_DP_MST; | |
141 | goto out; | |
142 | } else if (ret != 0) { | |
143 | goto out; | |
144 | } | |
6ba11932 | 145 | } |
a0922278 | 146 | ret = NOUVEAU_DP_SST; |
52aa30f2 | 147 | |
a0922278 LP |
148 | out: |
149 | if (mstm && !mstm->suspended && ret != NOUVEAU_DP_MST) | |
150 | nv50_mstm_remove(mstm); | |
151 | ||
152 | mutex_unlock(&nv_encoder->dp.hpd_irq_lock); | |
52aa30f2 | 153 | return ret; |
6ee73861 | 154 | } |
d6a9efec | 155 | |
a0922278 LP |
156 | void nouveau_dp_irq(struct nouveau_drm *drm, |
157 | struct nouveau_connector *nv_connector) | |
158 | { | |
159 | struct drm_connector *connector = &nv_connector->base; | |
160 | struct nouveau_encoder *outp = find_encoder(connector, DCB_OUTPUT_DP); | |
161 | struct nv50_mstm *mstm; | |
162 | ||
163 | if (!outp) | |
164 | return; | |
165 | ||
166 | mstm = outp->dp.mstm; | |
167 | NV_DEBUG(drm, "service %s\n", connector->name); | |
168 | ||
169 | mutex_lock(&outp->dp.hpd_irq_lock); | |
170 | ||
171 | if (mstm && mstm->is_mst) { | |
172 | if (!nv50_mstm_service(drm, nv_connector, mstm)) | |
d297ce4b | 173 | nouveau_connector_hpd(connector); |
a0922278 LP |
174 | } else { |
175 | drm_dp_cec_irq(&nv_connector->aux); | |
176 | } | |
177 | ||
178 | mutex_unlock(&outp->dp.hpd_irq_lock); | |
179 | } | |
180 | ||
d6a9efec LP |
181 | /* TODO: |
182 | * - Use the minimum possible BPC here, once we add support for the max bpc | |
183 | * property. | |
d6a9efec LP |
184 | * - Validate against the DP caps advertised by the GPU (we don't check these |
185 | * yet) | |
186 | */ | |
187 | enum drm_mode_status | |
188 | nv50_dp_mode_valid(struct drm_connector *connector, | |
189 | struct nouveau_encoder *outp, | |
190 | const struct drm_display_mode *mode, | |
191 | unsigned *out_clock) | |
192 | { | |
193 | const unsigned min_clock = 25000; | |
409d3813 | 194 | unsigned max_clock, ds_clock, clock; |
d6a9efec LP |
195 | enum drm_mode_status ret; |
196 | ||
197 | if (mode->flags & DRM_MODE_FLAG_INTERLACE && !outp->caps.dp_interlace) | |
198 | return MODE_NO_INTERLACE; | |
199 | ||
200 | max_clock = outp->dp.link_nr * outp->dp.link_bw; | |
409d3813 LP |
201 | ds_clock = drm_dp_downstream_max_clock(outp->dp.dpcd, |
202 | outp->dp.downstream_ports); | |
203 | if (ds_clock) | |
204 | max_clock = min(max_clock, ds_clock); | |
d6a9efec | 205 | |
409d3813 | 206 | clock = mode->clock * (connector->display_info.bpc * 3) / 10; |
d6a9efec LP |
207 | ret = nouveau_conn_mode_clock_valid(mode, min_clock, max_clock, |
208 | &clock); | |
209 | if (out_clock) | |
210 | *out_clock = clock; | |
211 | return ret; | |
212 | } |