Commit | Line | Data |
---|---|---|
6ee73861 BS |
1 | /* |
2 | * Copyright (C) 2008 Maarten Maathuis. | |
3 | * All Rights Reserved. | |
4 | * | |
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: | |
12 | * | |
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. | |
16 | * | |
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. | |
24 | * | |
25 | */ | |
26 | ||
27 | #include "drmP.h" | |
28 | #include "drm_crtc_helper.h" | |
29 | ||
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" | |
38 | ||
39 | static void | |
ec7fc4a1 | 40 | nv50_dac_disconnect(struct drm_encoder *encoder) |
6ee73861 | 41 | { |
ec7fc4a1 BS |
42 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
43 | struct drm_device *dev = encoder->dev; | |
59c0f578 | 44 | struct nouveau_channel *evo = nv50_display(dev)->master; |
6ee73861 BS |
45 | int ret; |
46 | ||
ec7fc4a1 BS |
47 | if (!nv_encoder->crtc) |
48 | return; | |
835aadbe | 49 | nv50_crtc_blank(nouveau_crtc(nv_encoder->crtc), true); |
ec7fc4a1 | 50 | |
ef2bb506 | 51 | NV_DEBUG_KMS(dev, "Disconnecting DAC %d\n", nv_encoder->or); |
6ee73861 | 52 | |
835aadbe | 53 | ret = RING_SPACE(evo, 4); |
6ee73861 BS |
54 | if (ret) { |
55 | NV_ERROR(dev, "no space while disconnecting DAC\n"); | |
56 | return; | |
57 | } | |
6d597027 | 58 | BEGIN_NV04(evo, 0, NV50_EVO_DAC(nv_encoder->or, MODE_CTRL), 1); |
835aadbe | 59 | OUT_RING (evo, 0); |
6d597027 | 60 | BEGIN_NV04(evo, 0, NV50_EVO_UPDATE, 1); |
835aadbe | 61 | OUT_RING (evo, 0); |
ec7fc4a1 BS |
62 | |
63 | nv_encoder->crtc = NULL; | |
6ee73861 BS |
64 | } |
65 | ||
66 | static enum drm_connector_status | |
67 | nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) | |
68 | { | |
69 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); | |
70 | struct drm_device *dev = encoder->dev; | |
71 | struct drm_nouveau_private *dev_priv = dev->dev_private; | |
72 | enum drm_connector_status status = connector_status_disconnected; | |
73 | uint32_t dpms_state, load_pattern, load_state; | |
74 | int or = nv_encoder->or; | |
75 | ||
76 | nv_wr32(dev, NV50_PDISPLAY_DAC_CLK_CTRL1(or), 0x00000001); | |
77 | dpms_state = nv_rd32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or)); | |
78 | ||
79 | nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), | |
80 | 0x00150000 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING); | |
4b5c152a | 81 | if (!nv_wait(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), |
6ee73861 BS |
82 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING, 0)) { |
83 | NV_ERROR(dev, "timeout: DAC_DPMS_CTRL_PENDING(%d) == 0\n", or); | |
84 | NV_ERROR(dev, "DAC_DPMS_CTRL(%d) = 0x%08x\n", or, | |
85 | nv_rd32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or))); | |
86 | return status; | |
87 | } | |
88 | ||
89 | /* Use bios provided value if possible. */ | |
04a39c57 BS |
90 | if (dev_priv->vbios.dactestval) { |
91 | load_pattern = dev_priv->vbios.dactestval; | |
ef2bb506 | 92 | NV_DEBUG_KMS(dev, "Using bios provided load_pattern of %d\n", |
6ee73861 BS |
93 | load_pattern); |
94 | } else { | |
95 | load_pattern = 340; | |
ef2bb506 | 96 | NV_DEBUG_KMS(dev, "Using default load_pattern of %d\n", |
6ee73861 BS |
97 | load_pattern); |
98 | } | |
99 | ||
100 | nv_wr32(dev, NV50_PDISPLAY_DAC_LOAD_CTRL(or), | |
101 | NV50_PDISPLAY_DAC_LOAD_CTRL_ACTIVE | load_pattern); | |
102 | mdelay(45); /* give it some time to process */ | |
103 | load_state = nv_rd32(dev, NV50_PDISPLAY_DAC_LOAD_CTRL(or)); | |
104 | ||
105 | nv_wr32(dev, NV50_PDISPLAY_DAC_LOAD_CTRL(or), 0); | |
106 | nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), dpms_state | | |
107 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING); | |
108 | ||
109 | if ((load_state & NV50_PDISPLAY_DAC_LOAD_CTRL_PRESENT) == | |
110 | NV50_PDISPLAY_DAC_LOAD_CTRL_PRESENT) | |
111 | status = connector_status_connected; | |
112 | ||
113 | if (status == connector_status_connected) | |
ef2bb506 | 114 | NV_DEBUG_KMS(dev, "Load was detected on output with or %d\n", or); |
6ee73861 | 115 | else |
ef2bb506 | 116 | NV_DEBUG_KMS(dev, "Load was not detected on output with or %d\n", or); |
6ee73861 BS |
117 | |
118 | return status; | |
119 | } | |
120 | ||
121 | static void | |
122 | nv50_dac_dpms(struct drm_encoder *encoder, int mode) | |
123 | { | |
124 | struct drm_device *dev = encoder->dev; | |
125 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); | |
126 | uint32_t val; | |
127 | int or = nv_encoder->or; | |
128 | ||
ef2bb506 | 129 | NV_DEBUG_KMS(dev, "or %d mode %d\n", or, mode); |
6ee73861 BS |
130 | |
131 | /* wait for it to be done */ | |
4b5c152a | 132 | if (!nv_wait(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), |
6ee73861 BS |
133 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING, 0)) { |
134 | NV_ERROR(dev, "timeout: DAC_DPMS_CTRL_PENDING(%d) == 0\n", or); | |
135 | NV_ERROR(dev, "DAC_DPMS_CTRL(%d) = 0x%08x\n", or, | |
136 | nv_rd32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or))); | |
137 | return; | |
138 | } | |
139 | ||
140 | val = nv_rd32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or)) & ~0x7F; | |
141 | ||
142 | if (mode != DRM_MODE_DPMS_ON) | |
143 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_BLANKED; | |
144 | ||
145 | switch (mode) { | |
146 | case DRM_MODE_DPMS_STANDBY: | |
147 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_HSYNC_OFF; | |
148 | break; | |
149 | case DRM_MODE_DPMS_SUSPEND: | |
150 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_VSYNC_OFF; | |
151 | break; | |
152 | case DRM_MODE_DPMS_OFF: | |
153 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_OFF; | |
154 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_HSYNC_OFF; | |
155 | val |= NV50_PDISPLAY_DAC_DPMS_CTRL_VSYNC_OFF; | |
156 | break; | |
157 | default: | |
158 | break; | |
159 | } | |
160 | ||
161 | nv_wr32(dev, NV50_PDISPLAY_DAC_DPMS_CTRL(or), val | | |
162 | NV50_PDISPLAY_DAC_DPMS_CTRL_PENDING); | |
163 | } | |
164 | ||
165 | static void | |
166 | nv50_dac_save(struct drm_encoder *encoder) | |
167 | { | |
168 | NV_ERROR(encoder->dev, "!!\n"); | |
169 | } | |
170 | ||
171 | static void | |
172 | nv50_dac_restore(struct drm_encoder *encoder) | |
173 | { | |
174 | NV_ERROR(encoder->dev, "!!\n"); | |
175 | } | |
176 | ||
177 | static bool | |
e811f5ae LP |
178 | nv50_dac_mode_fixup(struct drm_encoder *encoder, |
179 | const struct drm_display_mode *mode, | |
6ee73861 BS |
180 | struct drm_display_mode *adjusted_mode) |
181 | { | |
182 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); | |
183 | struct nouveau_connector *connector; | |
184 | ||
ef2bb506 | 185 | NV_DEBUG_KMS(encoder->dev, "or %d\n", nv_encoder->or); |
6ee73861 BS |
186 | |
187 | connector = nouveau_encoder_connector_get(nv_encoder); | |
188 | if (!connector) { | |
189 | NV_ERROR(encoder->dev, "Encoder has no connector\n"); | |
190 | return false; | |
191 | } | |
192 | ||
193 | if (connector->scaling_mode != DRM_MODE_SCALE_NONE && | |
c3c50e8b VS |
194 | connector->native_mode) |
195 | drm_mode_copy(adjusted_mode, connector->native_mode); | |
6ee73861 BS |
196 | |
197 | return true; | |
198 | } | |
199 | ||
6ee73861 BS |
200 | static void |
201 | nv50_dac_commit(struct drm_encoder *encoder) | |
202 | { | |
203 | } | |
204 | ||
205 | static void | |
206 | nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, | |
207 | struct drm_display_mode *adjusted_mode) | |
208 | { | |
209 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); | |
210 | struct drm_device *dev = encoder->dev; | |
59c0f578 | 211 | struct nouveau_channel *evo = nv50_display(dev)->master; |
6ee73861 BS |
212 | struct nouveau_crtc *crtc = nouveau_crtc(encoder->crtc); |
213 | uint32_t mode_ctl = 0, mode_ctl2 = 0; | |
214 | int ret; | |
215 | ||
04412921 BS |
216 | NV_DEBUG_KMS(dev, "or %d type %d crtc %d\n", |
217 | nv_encoder->or, nv_encoder->dcb->type, crtc->index); | |
6ee73861 BS |
218 | |
219 | nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON); | |
220 | ||
221 | if (crtc->index == 1) | |
222 | mode_ctl |= NV50_EVO_DAC_MODE_CTRL_CRTC1; | |
223 | else | |
224 | mode_ctl |= NV50_EVO_DAC_MODE_CTRL_CRTC0; | |
225 | ||
226 | /* Lacking a working tv-out, this is not a 100% sure. */ | |
227 | if (nv_encoder->dcb->type == OUTPUT_ANALOG) | |
228 | mode_ctl |= 0x40; | |
229 | else | |
230 | if (nv_encoder->dcb->type == OUTPUT_TV) | |
231 | mode_ctl |= 0x100; | |
232 | ||
233 | if (adjusted_mode->flags & DRM_MODE_FLAG_NHSYNC) | |
234 | mode_ctl2 |= NV50_EVO_DAC_MODE_CTRL2_NHSYNC; | |
235 | ||
236 | if (adjusted_mode->flags & DRM_MODE_FLAG_NVSYNC) | |
237 | mode_ctl2 |= NV50_EVO_DAC_MODE_CTRL2_NVSYNC; | |
238 | ||
239 | ret = RING_SPACE(evo, 3); | |
240 | if (ret) { | |
241 | NV_ERROR(dev, "no space while connecting DAC\n"); | |
242 | return; | |
243 | } | |
6d597027 | 244 | BEGIN_NV04(evo, 0, NV50_EVO_DAC(nv_encoder->or, MODE_CTRL), 2); |
6ee73861 BS |
245 | OUT_RING(evo, mode_ctl); |
246 | OUT_RING(evo, mode_ctl2); | |
ec7fc4a1 BS |
247 | |
248 | nv_encoder->crtc = encoder->crtc; | |
6ee73861 BS |
249 | } |
250 | ||
2107cce3 BS |
251 | static struct drm_crtc * |
252 | nv50_dac_crtc_get(struct drm_encoder *encoder) | |
253 | { | |
254 | return nouveau_encoder(encoder)->crtc; | |
255 | } | |
256 | ||
6ee73861 BS |
257 | static const struct drm_encoder_helper_funcs nv50_dac_helper_funcs = { |
258 | .dpms = nv50_dac_dpms, | |
259 | .save = nv50_dac_save, | |
260 | .restore = nv50_dac_restore, | |
261 | .mode_fixup = nv50_dac_mode_fixup, | |
7ae494e8 | 262 | .prepare = nv50_dac_disconnect, |
6ee73861 BS |
263 | .commit = nv50_dac_commit, |
264 | .mode_set = nv50_dac_mode_set, | |
2107cce3 | 265 | .get_crtc = nv50_dac_crtc_get, |
ec7fc4a1 BS |
266 | .detect = nv50_dac_detect, |
267 | .disable = nv50_dac_disconnect | |
6ee73861 BS |
268 | }; |
269 | ||
270 | static void | |
271 | nv50_dac_destroy(struct drm_encoder *encoder) | |
272 | { | |
273 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); | |
274 | ||
275 | if (!encoder) | |
276 | return; | |
277 | ||
ef2bb506 | 278 | NV_DEBUG_KMS(encoder->dev, "\n"); |
6ee73861 BS |
279 | |
280 | drm_encoder_cleanup(encoder); | |
281 | kfree(nv_encoder); | |
282 | } | |
283 | ||
284 | static const struct drm_encoder_funcs nv50_dac_encoder_funcs = { | |
285 | .destroy = nv50_dac_destroy, | |
286 | }; | |
287 | ||
288 | int | |
8f1a6086 | 289 | nv50_dac_create(struct drm_connector *connector, struct dcb_entry *entry) |
6ee73861 BS |
290 | { |
291 | struct nouveau_encoder *nv_encoder; | |
292 | struct drm_encoder *encoder; | |
293 | ||
6ee73861 BS |
294 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
295 | if (!nv_encoder) | |
296 | return -ENOMEM; | |
297 | encoder = to_drm_encoder(nv_encoder); | |
298 | ||
299 | nv_encoder->dcb = entry; | |
300 | nv_encoder->or = ffs(entry->or) - 1; | |
301 | ||
8f1a6086 | 302 | drm_encoder_init(connector->dev, encoder, &nv50_dac_encoder_funcs, |
6ee73861 BS |
303 | DRM_MODE_ENCODER_DAC); |
304 | drm_encoder_helper_add(encoder, &nv50_dac_helper_funcs); | |
305 | ||
306 | encoder->possible_crtcs = entry->heads; | |
307 | encoder->possible_clones = 0; | |
8f1a6086 BS |
308 | |
309 | drm_mode_connector_attach_encoder(connector, encoder); | |
6ee73861 BS |
310 | return 0; |
311 | } | |
312 |