2 * Copyright (C) 2008 Maarten Maathuis.
5 * Permission is hereby granted, free of charge, to any person obtaining
6 * a copy of this software and associated documentation files (the
7 * "Software"), to deal in the Software without restriction, including
8 * without limitation the rights to use, copy, modify, merge, publish,
9 * distribute, sublicense, and/or sell copies of the Software, and to
10 * permit persons to whom the Software is furnished to do so, subject to
11 * the following conditions:
13 * The above copyright notice and this permission notice (including the
14 * next paragraph) shall be included in all copies or substantial
15 * portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
18 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20 * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
21 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
22 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
23 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include "drm_crtc_helper.h"
30 #define NOUVEAU_DMA_DEBUG (nouveau_reg_debug & NOUVEAU_REG_DEBUG_EVO)
31 #include "nouveau_reg.h"
32 #include "nouveau_drv.h"
33 #include "nouveau_dma.h"
34 #include "nouveau_encoder.h"
35 #include "nouveau_connector.h"
36 #include "nouveau_crtc.h"
37 #include "nv50_display.h"
40 nv50_sor_disconnect(struct nouveau_encoder
*nv_encoder
)
42 struct drm_device
*dev
= to_drm_encoder(nv_encoder
)->dev
;
43 struct drm_nouveau_private
*dev_priv
= dev
->dev_private
;
44 struct nouveau_channel
*evo
= dev_priv
->evo
;
47 NV_DEBUG_KMS(dev
, "Disconnecting SOR %d\n", nv_encoder
->or);
49 ret
= RING_SPACE(evo
, 2);
51 NV_ERROR(dev
, "no space while disconnecting SOR\n");
54 BEGIN_RING(evo
, 0, NV50_EVO_SOR(nv_encoder
->or, MODE_CTRL
), 1);
59 nv50_sor_dp_link_train(struct drm_encoder
*encoder
)
61 struct drm_device
*dev
= encoder
->dev
;
62 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
63 struct bit_displayport_encoder_table
*dpe
;
66 dpe
= nouveau_bios_dp_table(dev
, nv_encoder
->dcb
, &dpe_headerlen
);
68 NV_ERROR(dev
, "SOR-%d: no DP encoder table!\n", nv_encoder
->or);
73 NV_DEBUG_KMS(dev
, "SOR-%d: running DP script 0\n", nv_encoder
->or);
74 nouveau_bios_run_init_table(dev
, le16_to_cpu(dpe
->script0
),
78 if (!nouveau_dp_link_train(encoder
))
79 NV_ERROR(dev
, "SOR-%d: link training failed\n", nv_encoder
->or);
82 NV_DEBUG_KMS(dev
, "SOR-%d: running DP script 1\n", nv_encoder
->or);
83 nouveau_bios_run_init_table(dev
, le16_to_cpu(dpe
->script1
),
89 nv50_sor_dpms(struct drm_encoder
*encoder
, int mode
)
91 struct drm_device
*dev
= encoder
->dev
;
92 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
93 struct drm_encoder
*enc
;
95 int or = nv_encoder
->or;
97 NV_DEBUG_KMS(dev
, "or %d mode %d\n", or, mode
);
99 nv_encoder
->last_dpms
= mode
;
100 list_for_each_entry(enc
, &dev
->mode_config
.encoder_list
, head
) {
101 struct nouveau_encoder
*nvenc
= nouveau_encoder(enc
);
103 if (nvenc
== nv_encoder
||
104 nvenc
->disconnect
!= nv50_sor_disconnect
||
105 nvenc
->dcb
->or != nv_encoder
->dcb
->or)
108 if (nvenc
->last_dpms
== DRM_MODE_DPMS_ON
)
112 /* wait for it to be done */
113 if (!nv_wait(NV50_PDISPLAY_SOR_DPMS_CTRL(or),
114 NV50_PDISPLAY_SOR_DPMS_CTRL_PENDING
, 0)) {
115 NV_ERROR(dev
, "timeout: SOR_DPMS_CTRL_PENDING(%d) == 0\n", or);
116 NV_ERROR(dev
, "SOR_DPMS_CTRL(%d) = 0x%08x\n", or,
117 nv_rd32(dev
, NV50_PDISPLAY_SOR_DPMS_CTRL(or)));
120 val
= nv_rd32(dev
, NV50_PDISPLAY_SOR_DPMS_CTRL(or));
122 if (mode
== DRM_MODE_DPMS_ON
)
123 val
|= NV50_PDISPLAY_SOR_DPMS_CTRL_ON
;
125 val
&= ~NV50_PDISPLAY_SOR_DPMS_CTRL_ON
;
127 nv_wr32(dev
, NV50_PDISPLAY_SOR_DPMS_CTRL(or), val
|
128 NV50_PDISPLAY_SOR_DPMS_CTRL_PENDING
);
129 if (!nv_wait(NV50_PDISPLAY_SOR_DPMS_STATE(or),
130 NV50_PDISPLAY_SOR_DPMS_STATE_WAIT
, 0)) {
131 NV_ERROR(dev
, "timeout: SOR_DPMS_STATE_WAIT(%d) == 0\n", or);
132 NV_ERROR(dev
, "SOR_DPMS_STATE(%d) = 0x%08x\n", or,
133 nv_rd32(dev
, NV50_PDISPLAY_SOR_DPMS_STATE(or)));
136 if (nv_encoder
->dcb
->type
== OUTPUT_DP
&& mode
== DRM_MODE_DPMS_ON
)
137 nv50_sor_dp_link_train(encoder
);
141 nv50_sor_save(struct drm_encoder
*encoder
)
143 NV_ERROR(encoder
->dev
, "!!\n");
147 nv50_sor_restore(struct drm_encoder
*encoder
)
149 NV_ERROR(encoder
->dev
, "!!\n");
153 nv50_sor_mode_fixup(struct drm_encoder
*encoder
, struct drm_display_mode
*mode
,
154 struct drm_display_mode
*adjusted_mode
)
156 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
157 struct nouveau_connector
*connector
;
159 NV_DEBUG_KMS(encoder
->dev
, "or %d\n", nv_encoder
->or);
161 connector
= nouveau_encoder_connector_get(nv_encoder
);
163 NV_ERROR(encoder
->dev
, "Encoder has no connector\n");
167 if (connector
->scaling_mode
!= DRM_MODE_SCALE_NONE
&&
168 connector
->native_mode
) {
169 int id
= adjusted_mode
->base
.id
;
170 *adjusted_mode
= *connector
->native_mode
;
171 adjusted_mode
->base
.id
= id
;
178 nv50_sor_prepare(struct drm_encoder
*encoder
)
183 nv50_sor_commit(struct drm_encoder
*encoder
)
188 nv50_sor_mode_set(struct drm_encoder
*encoder
, struct drm_display_mode
*mode
,
189 struct drm_display_mode
*adjusted_mode
)
191 struct drm_nouveau_private
*dev_priv
= encoder
->dev
->dev_private
;
192 struct nouveau_channel
*evo
= dev_priv
->evo
;
193 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
194 struct drm_device
*dev
= encoder
->dev
;
195 struct nouveau_crtc
*crtc
= nouveau_crtc(encoder
->crtc
);
196 uint32_t mode_ctl
= 0;
199 NV_DEBUG_KMS(dev
, "or %d\n", nv_encoder
->or);
201 nv50_sor_dpms(encoder
, DRM_MODE_DPMS_ON
);
203 switch (nv_encoder
->dcb
->type
) {
205 if (nv_encoder
->dcb
->sorconf
.link
& 1) {
206 if (adjusted_mode
->clock
< 165000)
214 mode_ctl
|= (nv_encoder
->dp
.mc_unknown
<< 16);
215 if (nv_encoder
->dcb
->sorconf
.link
& 1)
216 mode_ctl
|= 0x00000800;
218 mode_ctl
|= 0x00000900;
224 if (crtc
->index
== 1)
225 mode_ctl
|= NV50_EVO_SOR_MODE_CTRL_CRTC1
;
227 mode_ctl
|= NV50_EVO_SOR_MODE_CTRL_CRTC0
;
229 if (adjusted_mode
->flags
& DRM_MODE_FLAG_NHSYNC
)
230 mode_ctl
|= NV50_EVO_SOR_MODE_CTRL_NHSYNC
;
232 if (adjusted_mode
->flags
& DRM_MODE_FLAG_NVSYNC
)
233 mode_ctl
|= NV50_EVO_SOR_MODE_CTRL_NVSYNC
;
235 ret
= RING_SPACE(evo
, 2);
237 NV_ERROR(dev
, "no space while connecting SOR\n");
240 BEGIN_RING(evo
, 0, NV50_EVO_SOR(nv_encoder
->or, MODE_CTRL
), 1);
241 OUT_RING(evo
, mode_ctl
);
244 static const struct drm_encoder_helper_funcs nv50_sor_helper_funcs
= {
245 .dpms
= nv50_sor_dpms
,
246 .save
= nv50_sor_save
,
247 .restore
= nv50_sor_restore
,
248 .mode_fixup
= nv50_sor_mode_fixup
,
249 .prepare
= nv50_sor_prepare
,
250 .commit
= nv50_sor_commit
,
251 .mode_set
= nv50_sor_mode_set
,
256 nv50_sor_destroy(struct drm_encoder
*encoder
)
258 struct nouveau_encoder
*nv_encoder
= nouveau_encoder(encoder
);
263 NV_DEBUG_KMS(encoder
->dev
, "\n");
265 drm_encoder_cleanup(encoder
);
270 static const struct drm_encoder_funcs nv50_sor_encoder_funcs
= {
271 .destroy
= nv50_sor_destroy
,
275 nv50_sor_create(struct drm_device
*dev
, struct dcb_entry
*entry
)
277 struct nouveau_encoder
*nv_encoder
= NULL
;
278 struct drm_encoder
*encoder
;
282 NV_DEBUG_KMS(dev
, "\n");
284 switch (entry
->type
) {
286 NV_INFO(dev
, "Detected a TMDS output\n");
287 type
= DRM_MODE_ENCODER_TMDS
;
290 NV_INFO(dev
, "Detected a LVDS output\n");
291 type
= DRM_MODE_ENCODER_LVDS
;
293 if (nouveau_bios_parse_lvds_table(dev
, 0, &dum
, &dum
)) {
294 NV_ERROR(dev
, "Failed parsing LVDS table\n");
299 NV_INFO(dev
, "Detected a DP output\n");
300 type
= DRM_MODE_ENCODER_TMDS
;
306 nv_encoder
= kzalloc(sizeof(*nv_encoder
), GFP_KERNEL
);
309 encoder
= to_drm_encoder(nv_encoder
);
311 nv_encoder
->dcb
= entry
;
312 nv_encoder
->or = ffs(entry
->or) - 1;
314 nv_encoder
->disconnect
= nv50_sor_disconnect
;
316 drm_encoder_init(dev
, encoder
, &nv50_sor_encoder_funcs
, type
);
317 drm_encoder_helper_add(encoder
, &nv50_sor_helper_funcs
);
319 encoder
->possible_crtcs
= entry
->heads
;
320 encoder
->possible_clones
= 0;
322 if (nv_encoder
->dcb
->type
== OUTPUT_DP
) {
323 int or = nv_encoder
->or, link
= !(entry
->dpconf
.sor
.link
& 1);
326 tmp
= nv_rd32(dev
, 0x61c700 + (or * 0x800));
328 switch ((tmp
& 0x00000f00) >> 8) {
331 nv_encoder
->dp
.mc_unknown
= (tmp
& 0x000f0000) >> 16;
332 tmp
= nv_rd32(dev
, NV50_SOR_DP_CTRL(or, link
));
333 nv_encoder
->dp
.unk0
= tmp
& 0x000001fc;
334 tmp
= nv_rd32(dev
, NV50_SOR_DP_UNK128(or, link
));
335 nv_encoder
->dp
.unk1
= tmp
& 0x010f7f3f;
341 if (!nv_encoder
->dp
.mc_unknown
)
342 nv_encoder
->dp
.mc_unknown
= 5;