blob: 9e96eb12133a40c4ae70e8414474f5e6b496c564 [file] [log] [blame]
Ben Skeggs26f6d882011-07-04 16:25:18 +10001/*
2 * Copyright 2011 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
Ben Skeggs51beb422011-07-05 10:33:08 +100025#include <linux/dma-mapping.h>
Ben Skeggs83fc0832011-07-05 13:08:40 +100026
Ben Skeggs26f6d882011-07-04 16:25:18 +100027#include "drmP.h"
Ben Skeggs83fc0832011-07-05 13:08:40 +100028#include "drm_crtc_helper.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100029
30#include "nouveau_drv.h"
31#include "nouveau_connector.h"
32#include "nouveau_encoder.h"
33#include "nouveau_crtc.h"
Ben Skeggs37b034a2011-07-08 14:43:19 +100034#include "nouveau_dma.h"
Ben Skeggs438d99e2011-07-05 16:48:06 +100035#include "nouveau_fb.h"
Ben Skeggs3a89cd02011-07-07 10:47:10 +100036#include "nv50_display.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100037
38struct nvd0_display {
39 struct nouveau_gpuobj *mem;
Ben Skeggs51beb422011-07-05 10:33:08 +100040 struct {
41 dma_addr_t handle;
42 u32 *ptr;
43 } evo[1];
Ben Skeggsf20ce962011-07-08 13:17:01 +100044
45 struct tasklet_struct tasklet;
Ben Skeggsee417792011-07-08 14:34:45 +100046 u32 modeset;
Ben Skeggs26f6d882011-07-04 16:25:18 +100047};
48
49static struct nvd0_display *
50nvd0_display(struct drm_device *dev)
51{
52 struct drm_nouveau_private *dev_priv = dev->dev_private;
53 return dev_priv->engine.display.priv;
54}
55
Ben Skeggs37b034a2011-07-08 14:43:19 +100056static inline int
Ben Skeggs51beb422011-07-05 10:33:08 +100057evo_icmd(struct drm_device *dev, int id, u32 mthd, u32 data)
58{
59 int ret = 0;
60 nv_mask(dev, 0x610700 + (id * 0x10), 0x00000001, 0x00000001);
61 nv_wr32(dev, 0x610704 + (id * 0x10), data);
62 nv_mask(dev, 0x610704 + (id * 0x10), 0x80000ffc, 0x80000000 | mthd);
63 if (!nv_wait(dev, 0x610704 + (id * 0x10), 0x80000000, 0x00000000))
64 ret = -EBUSY;
65 nv_mask(dev, 0x610700 + (id * 0x10), 0x00000001, 0x00000000);
66 return ret;
67}
68
69static u32 *
70evo_wait(struct drm_device *dev, int id, int nr)
71{
72 struct nvd0_display *disp = nvd0_display(dev);
73 u32 put = nv_rd32(dev, 0x640000 + (id * 0x1000)) / 4;
74
75 if (put + nr >= (PAGE_SIZE / 4)) {
76 disp->evo[id].ptr[put] = 0x20000000;
77
78 nv_wr32(dev, 0x640000 + (id * 0x1000), 0x00000000);
79 if (!nv_wait(dev, 0x640004 + (id * 0x1000), ~0, 0x00000000)) {
80 NV_ERROR(dev, "evo %d dma stalled\n", id);
81 return NULL;
82 }
83
84 put = 0;
85 }
86
87 return disp->evo[id].ptr + put;
88}
89
90static void
91evo_kick(u32 *push, struct drm_device *dev, int id)
92{
93 struct nvd0_display *disp = nvd0_display(dev);
94 nv_wr32(dev, 0x640000 + (id * 0x1000), (push - disp->evo[id].ptr) << 2);
95}
96
97#define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
98#define evo_data(p,d) *((p)++) = (d)
99
Ben Skeggs83fc0832011-07-05 13:08:40 +1000100static struct drm_crtc *
101nvd0_display_crtc_get(struct drm_encoder *encoder)
102{
103 return nouveau_encoder(encoder)->crtc;
104}
105
Ben Skeggs26f6d882011-07-04 16:25:18 +1000106/******************************************************************************
Ben Skeggs438d99e2011-07-05 16:48:06 +1000107 * CRTC
108 *****************************************************************************/
109static int
Ben Skeggs488ff202011-10-17 10:38:10 +1000110nvd0_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000111{
Ben Skeggs488ff202011-10-17 10:38:10 +1000112 struct nouveau_connector *nv_connector;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000113 struct drm_device *dev = nv_crtc->base.dev;
Ben Skeggs488ff202011-10-17 10:38:10 +1000114 u32 *push, mode = 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000115
Ben Skeggs488ff202011-10-17 10:38:10 +1000116 nv_connector = nouveau_crtc_connector_get(nv_crtc);
117 if (nv_connector->use_dithering) {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000118 /* 0x11: 6bpc dynamic 2x2
119 * 0x13: 8bpc dynamic 2x2
120 * 0x19: 6bpc static 2x2
121 * 0x1b: 8bpc static 2x2
122 * 0x21: 6bpc temporal
123 * 0x23: 8bpc temporal
124 */
125 mode = 0x00000011;
126 }
127
128 push = evo_wait(dev, 0, 4);
129 if (push) {
130 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x300), 1);
131 evo_data(push, mode);
132 if (update) {
133 evo_mthd(push, 0x0080, 1);
134 evo_data(push, 0x00000000);
135 }
136 evo_kick(push, dev, 0);
137 }
138
139 return 0;
140}
141
142static int
Ben Skeggs488ff202011-10-17 10:38:10 +1000143nvd0_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000144{
145 struct drm_display_mode *mode = &nv_crtc->base.mode;
146 struct drm_device *dev = nv_crtc->base.dev;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000147 struct nouveau_connector *nv_connector;
148 u32 *push, outX, outY;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000149
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000150 outX = mode->hdisplay;
151 outY = mode->vdisplay;
152
153 nv_connector = nouveau_crtc_connector_get(nv_crtc);
154 if (nv_connector && nv_connector->native_mode) {
155 struct drm_display_mode *native = nv_connector->native_mode;
156 u32 xratio = (native->hdisplay << 19) / mode->hdisplay;
157 u32 yratio = (native->vdisplay << 19) / mode->vdisplay;
158
Ben Skeggs488ff202011-10-17 10:38:10 +1000159 switch (nv_connector->scaling_mode) {
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000160 case DRM_MODE_SCALE_ASPECT:
161 if (xratio > yratio) {
162 outX = (mode->hdisplay * yratio) >> 19;
163 outY = (mode->vdisplay * yratio) >> 19;
164 } else {
165 outX = (mode->hdisplay * xratio) >> 19;
166 outY = (mode->vdisplay * xratio) >> 19;
167 }
168 break;
169 case DRM_MODE_SCALE_FULLSCREEN:
170 outX = native->hdisplay;
171 outY = native->vdisplay;
172 break;
173 default:
174 break;
175 }
176 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000177
178 push = evo_wait(dev, 0, 16);
179 if (push) {
180 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000181 evo_data(push, (outY << 16) | outX);
182 evo_data(push, (outY << 16) | outX);
183 evo_data(push, (outY << 16) | outX);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000184 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
185 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000186 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
187 evo_data(push, (mode->vdisplay << 16) | mode->hdisplay);
188 if (update) {
189 evo_mthd(push, 0x0080, 1);
190 evo_data(push, 0x00000000);
191 }
192 evo_kick(push, dev, 0);
193 }
194
195 return 0;
196}
197
198static int
199nvd0_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
200 int x, int y, bool update)
201{
202 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
203 u32 *push;
204
Ben Skeggs438d99e2011-07-05 16:48:06 +1000205 push = evo_wait(fb->dev, 0, 16);
206 if (push) {
207 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
208 evo_data(push, nvfb->nvbo->bo.offset >> 8);
209 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
210 evo_data(push, (fb->height << 16) | fb->width);
211 evo_data(push, nvfb->r_pitch);
212 evo_data(push, nvfb->r_format);
Ben Skeggsc0cc92a2011-07-06 11:40:45 +1000213 evo_data(push, nvfb->r_dma);
Ben Skeggsc6f2f712011-07-08 12:11:58 +1000214 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
215 evo_data(push, (y << 16) | x);
Ben Skeggsa46232e2011-07-07 15:23:48 +1000216 if (update) {
217 evo_mthd(push, 0x0080, 1);
218 evo_data(push, 0x00000000);
219 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000220 evo_kick(push, fb->dev, 0);
221 }
222
Ben Skeggsc0cc92a2011-07-06 11:40:45 +1000223 nv_crtc->fb.tile_flags = nvfb->r_dma;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000224 return 0;
225}
226
227static void
228nvd0_crtc_cursor_show(struct nouveau_crtc *nv_crtc, bool show, bool update)
229{
230 struct drm_device *dev = nv_crtc->base.dev;
231 u32 *push = evo_wait(dev, 0, 16);
232 if (push) {
233 if (show) {
234 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
235 evo_data(push, 0x85000000);
236 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
237 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
Ben Skeggs37b034a2011-07-08 14:43:19 +1000238 evo_data(push, NvEvoVRAM);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000239 } else {
240 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
241 evo_data(push, 0x05000000);
242 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
243 evo_data(push, 0x00000000);
244 }
245
246 if (update) {
247 evo_mthd(push, 0x0080, 1);
248 evo_data(push, 0x00000000);
249 }
250
251 evo_kick(push, dev, 0);
252 }
253}
254
255static void
256nvd0_crtc_dpms(struct drm_crtc *crtc, int mode)
257{
258}
259
260static void
261nvd0_crtc_prepare(struct drm_crtc *crtc)
262{
263 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
264 u32 *push;
265
266 push = evo_wait(crtc->dev, 0, 2);
267 if (push) {
268 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
269 evo_data(push, 0x00000000);
270 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
271 evo_data(push, 0x03000000);
272 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
273 evo_data(push, 0x00000000);
274 evo_kick(push, crtc->dev, 0);
275 }
276
277 nvd0_crtc_cursor_show(nv_crtc, false, false);
278}
279
280static void
281nvd0_crtc_commit(struct drm_crtc *crtc)
282{
283 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
284 u32 *push;
285
286 push = evo_wait(crtc->dev, 0, 32);
287 if (push) {
288 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
289 evo_data(push, nv_crtc->fb.tile_flags);
290 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
291 evo_data(push, 0x83000000);
292 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
293 evo_data(push, 0x00000000);
294 evo_data(push, 0x00000000);
295 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
Ben Skeggs37b034a2011-07-08 14:43:19 +1000296 evo_data(push, NvEvoVRAM);
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +1000297 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
298 evo_data(push, 0xffffff00);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000299 evo_kick(push, crtc->dev, 0);
300 }
301
302 nvd0_crtc_cursor_show(nv_crtc, nv_crtc->cursor.visible, true);
303}
304
305static bool
306nvd0_crtc_mode_fixup(struct drm_crtc *crtc, struct drm_display_mode *mode,
307 struct drm_display_mode *adjusted_mode)
308{
309 return true;
310}
311
312static int
313nvd0_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
314{
315 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->fb);
316 int ret;
317
318 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
319 if (ret)
320 return ret;
321
322 if (old_fb) {
323 nvfb = nouveau_framebuffer(old_fb);
324 nouveau_bo_unpin(nvfb->nvbo);
325 }
326
327 return 0;
328}
329
330static int
331nvd0_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
332 struct drm_display_mode *mode, int x, int y,
333 struct drm_framebuffer *old_fb)
334{
335 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
336 struct nouveau_connector *nv_connector;
337 u32 htotal = mode->htotal;
338 u32 vtotal = mode->vtotal;
339 u32 hsyncw = mode->hsync_end - mode->hsync_start - 1;
340 u32 vsyncw = mode->vsync_end - mode->vsync_start - 1;
341 u32 hfrntp = mode->hsync_start - mode->hdisplay;
342 u32 vfrntp = mode->vsync_start - mode->vdisplay;
343 u32 hbackp = mode->htotal - mode->hsync_end;
344 u32 vbackp = mode->vtotal - mode->vsync_end;
345 u32 hss2be = hsyncw + hbackp;
346 u32 vss2be = vsyncw + vbackp;
347 u32 hss2de = htotal - hfrntp;
348 u32 vss2de = vtotal - vfrntp;
Ben Skeggs629c1b92011-07-08 09:43:20 +1000349 u32 syncs, *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000350 int ret;
351
Ben Skeggs629c1b92011-07-08 09:43:20 +1000352 syncs = 0x00000001;
353 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
354 syncs |= 0x00000008;
355 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
356 syncs |= 0x00000010;
357
Ben Skeggs438d99e2011-07-05 16:48:06 +1000358 ret = nvd0_crtc_swap_fbs(crtc, old_fb);
359 if (ret)
360 return ret;
361
362 push = evo_wait(crtc->dev, 0, 64);
363 if (push) {
364 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 5);
Ben Skeggs629c1b92011-07-08 09:43:20 +1000365 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000366 evo_data(push, (vtotal << 16) | htotal);
367 evo_data(push, (vsyncw << 16) | hsyncw);
368 evo_data(push, (vss2be << 16) | hss2be);
369 evo_data(push, (vss2de << 16) | hss2de);
370 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
371 evo_data(push, 0x00000000); /* ??? */
372 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
373 evo_data(push, mode->clock * 1000);
374 evo_data(push, 0x00200000); /* ??? */
375 evo_data(push, mode->clock * 1000);
Ben Skeggs629c1b92011-07-08 09:43:20 +1000376 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 1);
377 evo_data(push, syncs);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000378 evo_kick(push, crtc->dev, 0);
379 }
380
381 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggs488ff202011-10-17 10:38:10 +1000382 nvd0_crtc_set_dither(nv_crtc, false);
383 nvd0_crtc_set_scale(nv_crtc, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000384 nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, false);
385 return 0;
386}
387
388static int
389nvd0_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
390 struct drm_framebuffer *old_fb)
391{
392 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
393 int ret;
394
Ben Skeggs84e2ad82011-08-26 09:40:39 +1000395 if (!crtc->fb) {
396 NV_DEBUG_KMS(crtc->dev, "No FB bound\n");
397 return 0;
398 }
399
Ben Skeggs438d99e2011-07-05 16:48:06 +1000400 ret = nvd0_crtc_swap_fbs(crtc, old_fb);
401 if (ret)
402 return ret;
403
404 nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, true);
405 return 0;
406}
407
408static int
409nvd0_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
410 struct drm_framebuffer *fb, int x, int y,
411 enum mode_set_atomic state)
412{
413 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
414 nvd0_crtc_set_image(nv_crtc, fb, x, y, true);
415 return 0;
416}
417
418static void
419nvd0_crtc_lut_load(struct drm_crtc *crtc)
420{
421 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
422 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
423 int i;
424
425 for (i = 0; i < 256; i++) {
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +1000426 writew(0x6000 + (nv_crtc->lut.r[i] >> 2), lut + (i * 0x20) + 0);
427 writew(0x6000 + (nv_crtc->lut.g[i] >> 2), lut + (i * 0x20) + 2);
428 writew(0x6000 + (nv_crtc->lut.b[i] >> 2), lut + (i * 0x20) + 4);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000429 }
430}
431
432static int
433nvd0_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
434 uint32_t handle, uint32_t width, uint32_t height)
435{
436 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
437 struct drm_device *dev = crtc->dev;
438 struct drm_gem_object *gem;
439 struct nouveau_bo *nvbo;
440 bool visible = (handle != 0);
441 int i, ret = 0;
442
443 if (visible) {
444 if (width != 64 || height != 64)
445 return -EINVAL;
446
447 gem = drm_gem_object_lookup(dev, file_priv, handle);
448 if (unlikely(!gem))
449 return -ENOENT;
450 nvbo = nouveau_gem_object(gem);
451
452 ret = nouveau_bo_map(nvbo);
453 if (ret == 0) {
454 for (i = 0; i < 64 * 64; i++) {
455 u32 v = nouveau_bo_rd32(nvbo, i);
456 nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v);
457 }
458 nouveau_bo_unmap(nvbo);
459 }
460
461 drm_gem_object_unreference_unlocked(gem);
462 }
463
464 if (visible != nv_crtc->cursor.visible) {
465 nvd0_crtc_cursor_show(nv_crtc, visible, true);
466 nv_crtc->cursor.visible = visible;
467 }
468
469 return ret;
470}
471
472static int
473nvd0_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
474{
475 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
476 const u32 data = (y << 16) | x;
477
478 nv_wr32(crtc->dev, 0x64d084 + (nv_crtc->index * 0x1000), data);
479 nv_wr32(crtc->dev, 0x64d080 + (nv_crtc->index * 0x1000), 0x00000000);
480 return 0;
481}
482
483static void
484nvd0_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
485 uint32_t start, uint32_t size)
486{
487 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
488 u32 end = max(start + size, (u32)256);
489 u32 i;
490
491 for (i = start; i < end; i++) {
492 nv_crtc->lut.r[i] = r[i];
493 nv_crtc->lut.g[i] = g[i];
494 nv_crtc->lut.b[i] = b[i];
495 }
496
497 nvd0_crtc_lut_load(crtc);
498}
499
500static void
501nvd0_crtc_destroy(struct drm_crtc *crtc)
502{
503 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
504 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
505 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
506 nouveau_bo_unmap(nv_crtc->lut.nvbo);
507 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
508 drm_crtc_cleanup(crtc);
509 kfree(crtc);
510}
511
512static const struct drm_crtc_helper_funcs nvd0_crtc_hfunc = {
513 .dpms = nvd0_crtc_dpms,
514 .prepare = nvd0_crtc_prepare,
515 .commit = nvd0_crtc_commit,
516 .mode_fixup = nvd0_crtc_mode_fixup,
517 .mode_set = nvd0_crtc_mode_set,
518 .mode_set_base = nvd0_crtc_mode_set_base,
519 .mode_set_base_atomic = nvd0_crtc_mode_set_base_atomic,
520 .load_lut = nvd0_crtc_lut_load,
521};
522
523static const struct drm_crtc_funcs nvd0_crtc_func = {
524 .cursor_set = nvd0_crtc_cursor_set,
525 .cursor_move = nvd0_crtc_cursor_move,
526 .gamma_set = nvd0_crtc_gamma_set,
527 .set_config = drm_crtc_helper_set_config,
528 .destroy = nvd0_crtc_destroy,
529};
530
Ben Skeggsc20ab3e2011-08-25 14:09:43 +1000531static void
532nvd0_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
533{
534}
535
536static void
537nvd0_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
538{
539}
540
Ben Skeggs438d99e2011-07-05 16:48:06 +1000541static int
542nvd0_crtc_create(struct drm_device *dev, int index)
543{
544 struct nouveau_crtc *nv_crtc;
545 struct drm_crtc *crtc;
546 int ret, i;
547
548 nv_crtc = kzalloc(sizeof(*nv_crtc), GFP_KERNEL);
549 if (!nv_crtc)
550 return -ENOMEM;
551
552 nv_crtc->index = index;
553 nv_crtc->set_dither = nvd0_crtc_set_dither;
554 nv_crtc->set_scale = nvd0_crtc_set_scale;
Ben Skeggsc20ab3e2011-08-25 14:09:43 +1000555 nv_crtc->cursor.set_offset = nvd0_cursor_set_offset;
556 nv_crtc->cursor.set_pos = nvd0_cursor_set_pos;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000557 for (i = 0; i < 256; i++) {
558 nv_crtc->lut.r[i] = i << 8;
559 nv_crtc->lut.g[i] = i << 8;
560 nv_crtc->lut.b[i] = i << 8;
561 }
562
563 crtc = &nv_crtc->base;
564 drm_crtc_init(dev, crtc, &nvd0_crtc_func);
565 drm_crtc_helper_add(crtc, &nvd0_crtc_hfunc);
566 drm_mode_crtc_set_gamma_size(crtc, 256);
567
568 ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM,
569 0, 0x0000, &nv_crtc->cursor.nvbo);
570 if (!ret) {
571 ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
572 if (!ret)
573 ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
574 if (ret)
575 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
576 }
577
578 if (ret)
579 goto out;
580
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +1000581 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000582 0, 0x0000, &nv_crtc->lut.nvbo);
583 if (!ret) {
584 ret = nouveau_bo_pin(nv_crtc->lut.nvbo, TTM_PL_FLAG_VRAM);
585 if (!ret)
586 ret = nouveau_bo_map(nv_crtc->lut.nvbo);
587 if (ret)
588 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
589 }
590
591 if (ret)
592 goto out;
593
594 nvd0_crtc_lut_load(crtc);
595
596out:
597 if (ret)
598 nvd0_crtc_destroy(crtc);
599 return ret;
600}
601
602/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +1000603 * DAC
604 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000605static void
606nvd0_dac_dpms(struct drm_encoder *encoder, int mode)
607{
608 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
609 struct drm_device *dev = encoder->dev;
610 int or = nv_encoder->or;
611 u32 dpms_ctrl;
612
613 dpms_ctrl = 0x80000000;
614 if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF)
615 dpms_ctrl |= 0x00000001;
616 if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF)
617 dpms_ctrl |= 0x00000004;
618
619 nv_wait(dev, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
620 nv_mask(dev, 0x61a004 + (or * 0x0800), 0xc000007f, dpms_ctrl);
621 nv_wait(dev, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
622}
623
624static bool
625nvd0_dac_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
626 struct drm_display_mode *adjusted_mode)
627{
628 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
629 struct nouveau_connector *nv_connector;
630
631 nv_connector = nouveau_encoder_connector_get(nv_encoder);
632 if (nv_connector && nv_connector->native_mode) {
633 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
634 int id = adjusted_mode->base.id;
635 *adjusted_mode = *nv_connector->native_mode;
636 adjusted_mode->base.id = id;
637 }
638 }
639
640 return true;
641}
642
643static void
644nvd0_dac_prepare(struct drm_encoder *encoder)
645{
646}
647
648static void
649nvd0_dac_commit(struct drm_encoder *encoder)
650{
651}
652
653static void
654nvd0_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
655 struct drm_display_mode *adjusted_mode)
656{
657 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
658 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
659 u32 *push;
660
661 nvd0_dac_dpms(encoder, DRM_MODE_DPMS_ON);
662
Ben Skeggsff8ff502011-07-08 11:53:37 +1000663 push = evo_wait(encoder->dev, 0, 4);
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000664 if (push) {
Ben Skeggsff8ff502011-07-08 11:53:37 +1000665 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x20), 2);
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000666 evo_data(push, 1 << nv_crtc->index);
Ben Skeggsff8ff502011-07-08 11:53:37 +1000667 evo_data(push, 0x00ff);
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000668 evo_kick(push, encoder->dev, 0);
669 }
670
671 nv_encoder->crtc = encoder->crtc;
672}
673
674static void
675nvd0_dac_disconnect(struct drm_encoder *encoder)
676{
677 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
678 struct drm_device *dev = encoder->dev;
679 u32 *push;
680
681 if (nv_encoder->crtc) {
682 nvd0_crtc_prepare(nv_encoder->crtc);
683
684 push = evo_wait(dev, 0, 4);
685 if (push) {
686 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x20), 1);
687 evo_data(push, 0x00000000);
688 evo_mthd(push, 0x0080, 1);
689 evo_data(push, 0x00000000);
690 evo_kick(push, dev, 0);
691 }
692
693 nv_encoder->crtc = NULL;
694 }
695}
696
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +1000697static enum drm_connector_status
698nvd0_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
699{
Ben Skeggsb6819932011-07-08 11:14:50 +1000700 enum drm_connector_status status = connector_status_disconnected;
701 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
702 struct drm_device *dev = encoder->dev;
703 int or = nv_encoder->or;
704 u32 load;
705
706 nv_wr32(dev, 0x61a00c + (or * 0x800), 0x00100000);
707 udelay(9500);
708 nv_wr32(dev, 0x61a00c + (or * 0x800), 0x80000000);
709
710 load = nv_rd32(dev, 0x61a00c + (or * 0x800));
711 if ((load & 0x38000000) == 0x38000000)
712 status = connector_status_connected;
713
714 nv_wr32(dev, 0x61a00c + (or * 0x800), 0x00000000);
715 return status;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +1000716}
717
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000718static void
719nvd0_dac_destroy(struct drm_encoder *encoder)
720{
721 drm_encoder_cleanup(encoder);
722 kfree(encoder);
723}
724
725static const struct drm_encoder_helper_funcs nvd0_dac_hfunc = {
726 .dpms = nvd0_dac_dpms,
727 .mode_fixup = nvd0_dac_mode_fixup,
728 .prepare = nvd0_dac_prepare,
729 .commit = nvd0_dac_commit,
730 .mode_set = nvd0_dac_mode_set,
731 .disable = nvd0_dac_disconnect,
732 .get_crtc = nvd0_display_crtc_get,
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +1000733 .detect = nvd0_dac_detect
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000734};
735
736static const struct drm_encoder_funcs nvd0_dac_func = {
737 .destroy = nvd0_dac_destroy,
738};
739
740static int
741nvd0_dac_create(struct drm_connector *connector, struct dcb_entry *dcbe)
742{
743 struct drm_device *dev = connector->dev;
744 struct nouveau_encoder *nv_encoder;
745 struct drm_encoder *encoder;
746
747 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
748 if (!nv_encoder)
749 return -ENOMEM;
750 nv_encoder->dcb = dcbe;
751 nv_encoder->or = ffs(dcbe->or) - 1;
752
753 encoder = to_drm_encoder(nv_encoder);
754 encoder->possible_crtcs = dcbe->heads;
755 encoder->possible_clones = 0;
756 drm_encoder_init(dev, encoder, &nvd0_dac_func, DRM_MODE_ENCODER_DAC);
757 drm_encoder_helper_add(encoder, &nvd0_dac_hfunc);
758
759 drm_mode_connector_attach_encoder(connector, encoder);
760 return 0;
761}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000762
763/******************************************************************************
764 * SOR
765 *****************************************************************************/
Ben Skeggs83fc0832011-07-05 13:08:40 +1000766static void
767nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
768{
769 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
770 struct drm_device *dev = encoder->dev;
771 struct drm_encoder *partner;
772 int or = nv_encoder->or;
773 u32 dpms_ctrl;
774
775 nv_encoder->last_dpms = mode;
776
777 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
778 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
779
780 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
781 continue;
782
783 if (nv_partner != nv_encoder &&
Ben Skeggs26cfa812011-11-17 09:10:02 +1000784 nv_partner->dcb->or == nv_encoder->dcb->or) {
Ben Skeggs83fc0832011-07-05 13:08:40 +1000785 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
786 return;
787 break;
788 }
789 }
790
791 dpms_ctrl = (mode == DRM_MODE_DPMS_ON);
792 dpms_ctrl |= 0x80000000;
793
794 nv_wait(dev, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
795 nv_mask(dev, 0x61c004 + (or * 0x0800), 0x80000001, dpms_ctrl);
796 nv_wait(dev, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
797 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
798}
799
800static bool
801nvd0_sor_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
802 struct drm_display_mode *adjusted_mode)
803{
804 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
805 struct nouveau_connector *nv_connector;
806
807 nv_connector = nouveau_encoder_connector_get(nv_encoder);
808 if (nv_connector && nv_connector->native_mode) {
809 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
810 int id = adjusted_mode->base.id;
811 *adjusted_mode = *nv_connector->native_mode;
812 adjusted_mode->base.id = id;
813 }
814 }
815
816 return true;
817}
818
819static void
820nvd0_sor_prepare(struct drm_encoder *encoder)
821{
822}
823
824static void
825nvd0_sor_commit(struct drm_encoder *encoder)
826{
827}
828
829static void
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000830nvd0_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
831 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +1000832{
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000833 struct drm_nouveau_private *dev_priv = encoder->dev->dev_private;
Ben Skeggs83fc0832011-07-05 13:08:40 +1000834 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
835 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000836 struct nouveau_connector *nv_connector;
837 struct nvbios *bios = &dev_priv->vbios;
Ben Skeggs83fc0832011-07-05 13:08:40 +1000838 u32 mode_ctrl = (1 << nv_crtc->index);
Ben Skeggsff8ff502011-07-08 11:53:37 +1000839 u32 *push, or_config;
Ben Skeggs83fc0832011-07-05 13:08:40 +1000840
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000841 nv_connector = nouveau_encoder_connector_get(nv_encoder);
842 switch (nv_encoder->dcb->type) {
843 case OUTPUT_TMDS:
844 if (nv_encoder->dcb->sorconf.link & 1) {
845 if (mode->clock < 165000)
846 mode_ctrl |= 0x00000100;
847 else
848 mode_ctrl |= 0x00000500;
849 } else {
850 mode_ctrl |= 0x00000200;
851 }
Ben Skeggs83fc0832011-07-05 13:08:40 +1000852
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000853 or_config = (mode_ctrl & 0x00000f00) >> 8;
854 if (mode->clock >= 165000)
855 or_config |= 0x0100;
856 break;
857 case OUTPUT_LVDS:
858 or_config = (mode_ctrl & 0x00000f00) >> 8;
859 if (bios->fp_no_ddc) {
860 if (bios->fp.dual_link)
861 or_config |= 0x0100;
862 if (bios->fp.if_is_24bit)
863 or_config |= 0x0200;
864 } else {
865 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS_SPWG) {
866 if (((u8 *)nv_connector->edid)[121] == 2)
867 or_config |= 0x0100;
868 } else
869 if (mode->clock >= bios->fp.duallink_transition_clk) {
870 or_config |= 0x0100;
871 }
872
873 if (or_config & 0x0100) {
874 if (bios->fp.strapless_is_24bit & 2)
875 or_config |= 0x0200;
876 } else {
877 if (bios->fp.strapless_is_24bit & 1)
878 or_config |= 0x0200;
879 }
880
881 if (nv_connector->base.display_info.bpc == 8)
882 or_config |= 0x0200;
883
884 }
885 break;
886 default:
887 BUG_ON(1);
888 break;
889 }
Ben Skeggsff8ff502011-07-08 11:53:37 +1000890
Ben Skeggs83fc0832011-07-05 13:08:40 +1000891 nvd0_sor_dpms(encoder, DRM_MODE_DPMS_ON);
892
Ben Skeggsff8ff502011-07-08 11:53:37 +1000893 push = evo_wait(encoder->dev, 0, 4);
Ben Skeggs83fc0832011-07-05 13:08:40 +1000894 if (push) {
Ben Skeggsff8ff502011-07-08 11:53:37 +1000895 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 2);
Ben Skeggs83fc0832011-07-05 13:08:40 +1000896 evo_data(push, mode_ctrl);
Ben Skeggsff8ff502011-07-08 11:53:37 +1000897 evo_data(push, or_config);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000898 evo_kick(push, encoder->dev, 0);
Ben Skeggs83fc0832011-07-05 13:08:40 +1000899 }
900
901 nv_encoder->crtc = encoder->crtc;
902}
903
904static void
905nvd0_sor_disconnect(struct drm_encoder *encoder)
906{
907 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
908 struct drm_device *dev = encoder->dev;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000909 u32 *push;
Ben Skeggs83fc0832011-07-05 13:08:40 +1000910
911 if (nv_encoder->crtc) {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000912 nvd0_crtc_prepare(nv_encoder->crtc);
913
914 push = evo_wait(dev, 0, 4);
Ben Skeggs83fc0832011-07-05 13:08:40 +1000915 if (push) {
916 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
917 evo_data(push, 0x00000000);
918 evo_mthd(push, 0x0080, 1);
919 evo_data(push, 0x00000000);
920 evo_kick(push, dev, 0);
921 }
922
923 nv_encoder->crtc = NULL;
924 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
925 }
926}
927
928static void
929nvd0_sor_destroy(struct drm_encoder *encoder)
930{
931 drm_encoder_cleanup(encoder);
932 kfree(encoder);
933}
934
935static const struct drm_encoder_helper_funcs nvd0_sor_hfunc = {
936 .dpms = nvd0_sor_dpms,
937 .mode_fixup = nvd0_sor_mode_fixup,
938 .prepare = nvd0_sor_prepare,
939 .commit = nvd0_sor_commit,
940 .mode_set = nvd0_sor_mode_set,
941 .disable = nvd0_sor_disconnect,
942 .get_crtc = nvd0_display_crtc_get,
943};
944
945static const struct drm_encoder_funcs nvd0_sor_func = {
946 .destroy = nvd0_sor_destroy,
947};
948
949static int
950nvd0_sor_create(struct drm_connector *connector, struct dcb_entry *dcbe)
951{
952 struct drm_device *dev = connector->dev;
953 struct nouveau_encoder *nv_encoder;
954 struct drm_encoder *encoder;
955
956 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
957 if (!nv_encoder)
958 return -ENOMEM;
959 nv_encoder->dcb = dcbe;
960 nv_encoder->or = ffs(dcbe->or) - 1;
961 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
962
963 encoder = to_drm_encoder(nv_encoder);
964 encoder->possible_crtcs = dcbe->heads;
965 encoder->possible_clones = 0;
966 drm_encoder_init(dev, encoder, &nvd0_sor_func, DRM_MODE_ENCODER_TMDS);
967 drm_encoder_helper_add(encoder, &nvd0_sor_hfunc);
968
969 drm_mode_connector_attach_encoder(connector, encoder);
970 return 0;
971}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000972
973/******************************************************************************
974 * IRQ
975 *****************************************************************************/
Ben Skeggs3a89cd02011-07-07 10:47:10 +1000976static struct dcb_entry *
977lookup_dcb(struct drm_device *dev, int id, u32 mc)
978{
979 struct drm_nouveau_private *dev_priv = dev->dev_private;
980 int type, or, i;
981
982 if (id < 4) {
983 type = OUTPUT_ANALOG;
984 or = id;
985 } else {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000986 switch (mc & 0x00000f00) {
987 case 0x00000000: type = OUTPUT_LVDS; break;
988 case 0x00000100: type = OUTPUT_TMDS; break;
989 case 0x00000200: type = OUTPUT_TMDS; break;
990 case 0x00000500: type = OUTPUT_TMDS; break;
991 default:
Ben Skeggsee417792011-07-08 14:34:45 +1000992 NV_ERROR(dev, "PDISP: unknown SOR mc 0x%08x\n", mc);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000993 return NULL;
994 }
995
996 or = id - 4;
Ben Skeggs3a89cd02011-07-07 10:47:10 +1000997 }
998
999 for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
1000 struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
1001 if (dcb->type == type && (dcb->or & (1 << or)))
1002 return dcb;
1003 }
1004
Ben Skeggsee417792011-07-08 14:34:45 +10001005 NV_ERROR(dev, "PDISP: DCB for %d/0x%08x not found\n", id, mc);
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001006 return NULL;
1007}
1008
Ben Skeggs46005222011-07-05 11:01:13 +10001009static void
Ben Skeggs37b034a2011-07-08 14:43:19 +10001010nvd0_display_unk1_handler(struct drm_device *dev, u32 crtc, u32 mask)
Ben Skeggs270a5742011-07-05 14:16:05 +10001011{
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001012 struct dcb_entry *dcb;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001013 int i;
1014
Ben Skeggsee417792011-07-08 14:34:45 +10001015 for (i = 0; mask && i < 8; i++) {
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001016 u32 mcc = nv_rd32(dev, 0x640180 + (i * 0x20));
Ben Skeggsee417792011-07-08 14:34:45 +10001017 if (!(mcc & (1 << crtc)))
1018 continue;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001019
Ben Skeggsee417792011-07-08 14:34:45 +10001020 dcb = lookup_dcb(dev, i, mcc);
1021 if (!dcb)
1022 continue;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001023
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001024 nouveau_bios_run_display_table(dev, 0x0000, -1, dcb, crtc);
Ben Skeggsee417792011-07-08 14:34:45 +10001025 }
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001026
Ben Skeggs270a5742011-07-05 14:16:05 +10001027 nv_wr32(dev, 0x6101d4, 0x00000000);
1028 nv_wr32(dev, 0x6109d4, 0x00000000);
1029 nv_wr32(dev, 0x6101d0, 0x80000000);
1030}
1031
1032static void
Ben Skeggs37b034a2011-07-08 14:43:19 +10001033nvd0_display_unk2_handler(struct drm_device *dev, u32 crtc, u32 mask)
Ben Skeggs270a5742011-07-05 14:16:05 +10001034{
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001035 struct dcb_entry *dcb;
Ben Skeggs37b034a2011-07-08 14:43:19 +10001036 u32 or, tmp, pclk;
Ben Skeggsee417792011-07-08 14:34:45 +10001037 int i;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001038
Ben Skeggsee417792011-07-08 14:34:45 +10001039 for (i = 0; mask && i < 8; i++) {
1040 u32 mcc = nv_rd32(dev, 0x640180 + (i * 0x20));
1041 if (!(mcc & (1 << crtc)))
1042 continue;
1043
1044 dcb = lookup_dcb(dev, i, mcc);
1045 if (!dcb)
1046 continue;
1047
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001048 nouveau_bios_run_display_table(dev, 0x0000, -2, dcb, crtc);
Ben Skeggsee417792011-07-08 14:34:45 +10001049 }
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001050
Ben Skeggsee417792011-07-08 14:34:45 +10001051 pclk = nv_rd32(dev, 0x660450 + (crtc * 0x300)) / 1000;
1052 if (mask & 0x00010000) {
1053 nv50_crtc_set_clock(dev, crtc, pclk);
1054 }
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001055
Ben Skeggsee417792011-07-08 14:34:45 +10001056 for (i = 0; mask && i < 8; i++) {
1057 u32 mcp = nv_rd32(dev, 0x660180 + (i * 0x20));
1058 u32 cfg = nv_rd32(dev, 0x660184 + (i * 0x20));
1059 if (!(mcp & (1 << crtc)))
1060 continue;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001061
Ben Skeggsee417792011-07-08 14:34:45 +10001062 dcb = lookup_dcb(dev, i, mcp);
1063 if (!dcb)
1064 continue;
1065 or = ffs(dcb->or) - 1;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001066
Ben Skeggsee417792011-07-08 14:34:45 +10001067 nouveau_bios_run_display_table(dev, cfg, pclk, dcb, crtc);
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001068
Ben Skeggsee417792011-07-08 14:34:45 +10001069 nv_wr32(dev, 0x612200 + (crtc * 0x800), 0x00000000);
1070 switch (dcb->type) {
1071 case OUTPUT_ANALOG:
1072 nv_wr32(dev, 0x612280 + (or * 0x800), 0x00000000);
1073 break;
1074 case OUTPUT_TMDS:
1075 case OUTPUT_LVDS:
1076 if (cfg & 0x00000100)
1077 tmp = 0x00000101;
1078 else
1079 tmp = 0x00000000;
1080
1081 nv_mask(dev, 0x612300 + (or * 0x800), 0x00000707, tmp);
1082 break;
1083 default:
1084 break;
1085 }
1086
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001087 break;
1088 }
1089
Ben Skeggs270a5742011-07-05 14:16:05 +10001090 nv_wr32(dev, 0x6101d4, 0x00000000);
1091 nv_wr32(dev, 0x6109d4, 0x00000000);
1092 nv_wr32(dev, 0x6101d0, 0x80000000);
1093}
1094
1095static void
Ben Skeggs37b034a2011-07-08 14:43:19 +10001096nvd0_display_unk4_handler(struct drm_device *dev, u32 crtc, u32 mask)
Ben Skeggs270a5742011-07-05 14:16:05 +10001097{
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001098 struct dcb_entry *dcb;
Ben Skeggsee417792011-07-08 14:34:45 +10001099 int pclk, i;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001100
Ben Skeggsee417792011-07-08 14:34:45 +10001101 pclk = nv_rd32(dev, 0x660450 + (crtc * 0x300)) / 1000;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001102
Ben Skeggsee417792011-07-08 14:34:45 +10001103 for (i = 0; mask && i < 8; i++) {
1104 u32 mcp = nv_rd32(dev, 0x660180 + (i * 0x20));
1105 u32 cfg = nv_rd32(dev, 0x660184 + (i * 0x20));
1106 if (!(mcp & (1 << crtc)))
1107 continue;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001108
Ben Skeggsee417792011-07-08 14:34:45 +10001109 dcb = lookup_dcb(dev, i, mcp);
1110 if (!dcb)
1111 continue;
1112
1113 nouveau_bios_run_display_table(dev, cfg, -pclk, dcb, crtc);
1114 }
1115
Ben Skeggs270a5742011-07-05 14:16:05 +10001116 nv_wr32(dev, 0x6101d4, 0x00000000);
1117 nv_wr32(dev, 0x6109d4, 0x00000000);
1118 nv_wr32(dev, 0x6101d0, 0x80000000);
1119}
1120
1121static void
Ben Skeggsf20ce962011-07-08 13:17:01 +10001122nvd0_display_bh(unsigned long data)
1123{
1124 struct drm_device *dev = (struct drm_device *)data;
1125 struct nvd0_display *disp = nvd0_display(dev);
Ben Skeggs37b034a2011-07-08 14:43:19 +10001126 u32 mask, crtc;
1127 int i;
1128
1129 if (drm_debug & (DRM_UT_DRIVER | DRM_UT_KMS)) {
1130 NV_INFO(dev, "PDISP: modeset req %d\n", disp->modeset);
1131 NV_INFO(dev, " STAT: 0x%08x 0x%08x 0x%08x\n",
1132 nv_rd32(dev, 0x6101d0),
1133 nv_rd32(dev, 0x6101d4), nv_rd32(dev, 0x6109d4));
1134 for (i = 0; i < 8; i++) {
1135 NV_INFO(dev, " %s%d: 0x%08x 0x%08x\n",
1136 i < 4 ? "DAC" : "SOR", i,
1137 nv_rd32(dev, 0x640180 + (i * 0x20)),
1138 nv_rd32(dev, 0x660180 + (i * 0x20)));
1139 }
1140 }
1141
1142 mask = nv_rd32(dev, 0x6101d4);
1143 crtc = 0;
1144 if (!mask) {
1145 mask = nv_rd32(dev, 0x6109d4);
1146 crtc = 1;
1147 }
Ben Skeggsf20ce962011-07-08 13:17:01 +10001148
Ben Skeggsee417792011-07-08 14:34:45 +10001149 if (disp->modeset & 0x00000001)
Ben Skeggs37b034a2011-07-08 14:43:19 +10001150 nvd0_display_unk1_handler(dev, crtc, mask);
Ben Skeggsee417792011-07-08 14:34:45 +10001151 if (disp->modeset & 0x00000002)
Ben Skeggs37b034a2011-07-08 14:43:19 +10001152 nvd0_display_unk2_handler(dev, crtc, mask);
Ben Skeggsee417792011-07-08 14:34:45 +10001153 if (disp->modeset & 0x00000004)
Ben Skeggs37b034a2011-07-08 14:43:19 +10001154 nvd0_display_unk4_handler(dev, crtc, mask);
Ben Skeggsf20ce962011-07-08 13:17:01 +10001155}
1156
1157static void
Ben Skeggs46005222011-07-05 11:01:13 +10001158nvd0_display_intr(struct drm_device *dev)
1159{
Ben Skeggsf20ce962011-07-08 13:17:01 +10001160 struct nvd0_display *disp = nvd0_display(dev);
Ben Skeggs46005222011-07-05 11:01:13 +10001161 u32 intr = nv_rd32(dev, 0x610088);
1162
1163 if (intr & 0x00000002) {
1164 u32 stat = nv_rd32(dev, 0x61009c);
1165 int chid = ffs(stat) - 1;
1166 if (chid >= 0) {
1167 u32 mthd = nv_rd32(dev, 0x6101f0 + (chid * 12));
1168 u32 data = nv_rd32(dev, 0x6101f4 + (chid * 12));
1169 u32 unkn = nv_rd32(dev, 0x6101f8 + (chid * 12));
1170
1171 NV_INFO(dev, "EvoCh: chid %d mthd 0x%04x data 0x%08x "
1172 "0x%08x 0x%08x\n",
1173 chid, (mthd & 0x0000ffc), data, mthd, unkn);
1174 nv_wr32(dev, 0x61009c, (1 << chid));
1175 nv_wr32(dev, 0x6101f0 + (chid * 12), 0x90000000);
1176 }
1177
1178 intr &= ~0x00000002;
1179 }
1180
Ben Skeggs270a5742011-07-05 14:16:05 +10001181 if (intr & 0x00100000) {
1182 u32 stat = nv_rd32(dev, 0x6100ac);
1183
1184 if (stat & 0x00000007) {
Ben Skeggsee417792011-07-08 14:34:45 +10001185 disp->modeset = stat;
Ben Skeggsf20ce962011-07-08 13:17:01 +10001186 tasklet_schedule(&disp->tasklet);
Ben Skeggs270a5742011-07-05 14:16:05 +10001187
Ben Skeggsf20ce962011-07-08 13:17:01 +10001188 nv_wr32(dev, 0x6100ac, (stat & 0x00000007));
Ben Skeggs270a5742011-07-05 14:16:05 +10001189 stat &= ~0x00000007;
1190 }
1191
1192 if (stat) {
1193 NV_INFO(dev, "PDISP: unknown intr24 0x%08x\n", stat);
1194 nv_wr32(dev, 0x6100ac, stat);
1195 }
1196
1197 intr &= ~0x00100000;
1198 }
1199
Ben Skeggs46005222011-07-05 11:01:13 +10001200 if (intr & 0x01000000) {
1201 u32 stat = nv_rd32(dev, 0x6100bc);
1202 nv_wr32(dev, 0x6100bc, stat);
1203 intr &= ~0x01000000;
1204 }
1205
1206 if (intr & 0x02000000) {
1207 u32 stat = nv_rd32(dev, 0x6108bc);
1208 nv_wr32(dev, 0x6108bc, stat);
1209 intr &= ~0x02000000;
1210 }
1211
1212 if (intr)
1213 NV_INFO(dev, "PDISP: unknown intr 0x%08x\n", intr);
1214}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001215
1216/******************************************************************************
1217 * Init
1218 *****************************************************************************/
1219static void
1220nvd0_display_fini(struct drm_device *dev)
1221{
1222 int i;
1223
1224 /* fini cursors */
1225 for (i = 14; i >= 13; i--) {
1226 if (!(nv_rd32(dev, 0x610490 + (i * 0x10)) & 0x00000001))
1227 continue;
1228
1229 nv_mask(dev, 0x610490 + (i * 0x10), 0x00000001, 0x00000000);
1230 nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00000000);
1231 nv_mask(dev, 0x610090, 1 << i, 0x00000000);
1232 nv_mask(dev, 0x6100a0, 1 << i, 0x00000000);
1233 }
1234
1235 /* fini master */
1236 if (nv_rd32(dev, 0x610490) & 0x00000010) {
1237 nv_mask(dev, 0x610490, 0x00000010, 0x00000000);
1238 nv_mask(dev, 0x610490, 0x00000003, 0x00000000);
1239 nv_wait(dev, 0x610490, 0x80000000, 0x00000000);
1240 nv_mask(dev, 0x610090, 0x00000001, 0x00000000);
1241 nv_mask(dev, 0x6100a0, 0x00000001, 0x00000000);
1242 }
1243}
1244
1245int
1246nvd0_display_init(struct drm_device *dev)
1247{
1248 struct nvd0_display *disp = nvd0_display(dev);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001249 u32 *push;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001250 int i;
1251
1252 if (nv_rd32(dev, 0x6100ac) & 0x00000100) {
1253 nv_wr32(dev, 0x6100ac, 0x00000100);
1254 nv_mask(dev, 0x6194e8, 0x00000001, 0x00000000);
1255 if (!nv_wait(dev, 0x6194e8, 0x00000002, 0x00000000)) {
1256 NV_ERROR(dev, "PDISP: 0x6194e8 0x%08x\n",
1257 nv_rd32(dev, 0x6194e8));
1258 return -EBUSY;
1259 }
1260 }
1261
Ben Skeggsa36f04c2011-07-06 14:39:23 +10001262 /* nfi what these are exactly, i do know that SOR_MODE_CTRL won't
1263 * work at all unless you do the SOR part below.
1264 */
1265 for (i = 0; i < 3; i++) {
1266 u32 dac = nv_rd32(dev, 0x61a000 + (i * 0x800));
1267 nv_wr32(dev, 0x6101c0 + (i * 0x800), dac);
1268 }
1269
1270 for (i = 0; i < 4; i++) {
1271 u32 sor = nv_rd32(dev, 0x61c000 + (i * 0x800));
1272 nv_wr32(dev, 0x6301c4 + (i * 0x800), sor);
1273 }
1274
1275 for (i = 0; i < 2; i++) {
1276 u32 crtc0 = nv_rd32(dev, 0x616104 + (i * 0x800));
1277 u32 crtc1 = nv_rd32(dev, 0x616108 + (i * 0x800));
1278 u32 crtc2 = nv_rd32(dev, 0x61610c + (i * 0x800));
1279 nv_wr32(dev, 0x6101b4 + (i * 0x800), crtc0);
1280 nv_wr32(dev, 0x6101b8 + (i * 0x800), crtc1);
1281 nv_wr32(dev, 0x6101bc + (i * 0x800), crtc2);
1282 }
1283
1284 /* point at our hash table / objects, enable interrupts */
Ben Skeggs26f6d882011-07-04 16:25:18 +10001285 nv_wr32(dev, 0x610010, (disp->mem->vinst >> 8) | 9);
Ben Skeggs270a5742011-07-05 14:16:05 +10001286 nv_mask(dev, 0x6100b0, 0x00000307, 0x00000307);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001287
1288 /* init master */
Ben Skeggs51beb422011-07-05 10:33:08 +10001289 nv_wr32(dev, 0x610494, (disp->evo[0].handle >> 8) | 3);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001290 nv_wr32(dev, 0x610498, 0x00010000);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001291 nv_wr32(dev, 0x61049c, 0x00000001);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001292 nv_mask(dev, 0x610490, 0x00000010, 0x00000010);
1293 nv_wr32(dev, 0x640000, 0x00000000);
1294 nv_wr32(dev, 0x610490, 0x01000013);
1295 if (!nv_wait(dev, 0x610490, 0x80000000, 0x00000000)) {
1296 NV_ERROR(dev, "PDISP: master 0x%08x\n",
1297 nv_rd32(dev, 0x610490));
1298 return -EBUSY;
1299 }
1300 nv_mask(dev, 0x610090, 0x00000001, 0x00000001);
1301 nv_mask(dev, 0x6100a0, 0x00000001, 0x00000001);
1302
1303 /* init cursors */
1304 for (i = 13; i <= 14; i++) {
1305 nv_wr32(dev, 0x610490 + (i * 0x10), 0x00000001);
1306 if (!nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00010000)) {
1307 NV_ERROR(dev, "PDISP: curs%d 0x%08x\n", i,
1308 nv_rd32(dev, 0x610490 + (i * 0x10)));
1309 return -EBUSY;
1310 }
1311
1312 nv_mask(dev, 0x610090, 1 << i, 1 << i);
1313 nv_mask(dev, 0x6100a0, 1 << i, 1 << i);
1314 }
1315
Ben Skeggsefd272a2011-07-05 11:58:58 +10001316 push = evo_wait(dev, 0, 32);
1317 if (!push)
1318 return -EBUSY;
1319 evo_mthd(push, 0x0088, 1);
Ben Skeggs37b034a2011-07-08 14:43:19 +10001320 evo_data(push, NvEvoSync);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001321 evo_mthd(push, 0x0084, 1);
1322 evo_data(push, 0x00000000);
1323 evo_mthd(push, 0x0084, 1);
1324 evo_data(push, 0x80000000);
1325 evo_mthd(push, 0x008c, 1);
1326 evo_data(push, 0x00000000);
1327 evo_kick(push, dev, 0);
1328
Ben Skeggs26f6d882011-07-04 16:25:18 +10001329 return 0;
1330}
1331
1332void
1333nvd0_display_destroy(struct drm_device *dev)
1334{
1335 struct drm_nouveau_private *dev_priv = dev->dev_private;
1336 struct nvd0_display *disp = nvd0_display(dev);
Ben Skeggs51beb422011-07-05 10:33:08 +10001337 struct pci_dev *pdev = dev->pdev;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001338
1339 nvd0_display_fini(dev);
1340
Ben Skeggs51beb422011-07-05 10:33:08 +10001341 pci_free_consistent(pdev, PAGE_SIZE, disp->evo[0].ptr, disp->evo[0].handle);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001342 nouveau_gpuobj_ref(NULL, &disp->mem);
Ben Skeggs46005222011-07-05 11:01:13 +10001343 nouveau_irq_unregister(dev, 26);
Ben Skeggs51beb422011-07-05 10:33:08 +10001344
1345 dev_priv->engine.display.priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001346 kfree(disp);
1347}
1348
1349int
1350nvd0_display_create(struct drm_device *dev)
1351{
1352 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsefd272a2011-07-05 11:58:58 +10001353 struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001354 struct dcb_table *dcb = &dev_priv->vbios.dcb;
1355 struct drm_connector *connector, *tmp;
Ben Skeggs51beb422011-07-05 10:33:08 +10001356 struct pci_dev *pdev = dev->pdev;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001357 struct nvd0_display *disp;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001358 struct dcb_entry *dcbe;
1359 int ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001360
1361 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
1362 if (!disp)
1363 return -ENOMEM;
1364 dev_priv->engine.display.priv = disp;
1365
Ben Skeggs438d99e2011-07-05 16:48:06 +10001366 /* create crtc objects to represent the hw heads */
1367 for (i = 0; i < 2; i++) {
1368 ret = nvd0_crtc_create(dev, i);
1369 if (ret)
1370 goto out;
1371 }
1372
Ben Skeggs83fc0832011-07-05 13:08:40 +10001373 /* create encoder/connector objects based on VBIOS DCB table */
1374 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
1375 connector = nouveau_connector_create(dev, dcbe->connector);
1376 if (IS_ERR(connector))
1377 continue;
1378
1379 if (dcbe->location != DCB_LOC_ON_CHIP) {
1380 NV_WARN(dev, "skipping off-chip encoder %d/%d\n",
1381 dcbe->type, ffs(dcbe->or) - 1);
1382 continue;
1383 }
1384
1385 switch (dcbe->type) {
1386 case OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001387 case OUTPUT_LVDS:
Ben Skeggs83fc0832011-07-05 13:08:40 +10001388 nvd0_sor_create(connector, dcbe);
1389 break;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001390 case OUTPUT_ANALOG:
1391 nvd0_dac_create(connector, dcbe);
1392 break;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001393 default:
1394 NV_WARN(dev, "skipping unsupported encoder %d/%d\n",
1395 dcbe->type, ffs(dcbe->or) - 1);
1396 continue;
1397 }
1398 }
1399
1400 /* cull any connectors we created that don't have an encoder */
1401 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
1402 if (connector->encoder_ids[0])
1403 continue;
1404
1405 NV_WARN(dev, "%s has no encoders, removing\n",
1406 drm_get_connector_name(connector));
1407 connector->funcs->destroy(connector);
1408 }
1409
Ben Skeggs46005222011-07-05 11:01:13 +10001410 /* setup interrupt handling */
Ben Skeggsf20ce962011-07-08 13:17:01 +10001411 tasklet_init(&disp->tasklet, nvd0_display_bh, (unsigned long)dev);
Ben Skeggs46005222011-07-05 11:01:13 +10001412 nouveau_irq_register(dev, 26, nvd0_display_intr);
1413
Ben Skeggs51beb422011-07-05 10:33:08 +10001414 /* hash table and dma objects for the memory areas we care about */
Ben Skeggsefd272a2011-07-05 11:58:58 +10001415 ret = nouveau_gpuobj_new(dev, NULL, 0x4000, 0x10000,
1416 NVOBJ_FLAG_ZERO_ALLOC, &disp->mem);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001417 if (ret)
1418 goto out;
1419
Ben Skeggsefd272a2011-07-05 11:58:58 +10001420 nv_wo32(disp->mem, 0x1000, 0x00000049);
1421 nv_wo32(disp->mem, 0x1004, (disp->mem->vinst + 0x2000) >> 8);
1422 nv_wo32(disp->mem, 0x1008, (disp->mem->vinst + 0x2fff) >> 8);
1423 nv_wo32(disp->mem, 0x100c, 0x00000000);
1424 nv_wo32(disp->mem, 0x1010, 0x00000000);
1425 nv_wo32(disp->mem, 0x1014, 0x00000000);
Ben Skeggs37b034a2011-07-08 14:43:19 +10001426 nv_wo32(disp->mem, 0x0000, NvEvoSync);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001427 nv_wo32(disp->mem, 0x0004, (0x1000 << 9) | 0x00000001);
1428
Ben Skeggsc0cc92a2011-07-06 11:40:45 +10001429 nv_wo32(disp->mem, 0x1020, 0x00000049);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001430 nv_wo32(disp->mem, 0x1024, 0x00000000);
1431 nv_wo32(disp->mem, 0x1028, (dev_priv->vram_size - 1) >> 8);
1432 nv_wo32(disp->mem, 0x102c, 0x00000000);
1433 nv_wo32(disp->mem, 0x1030, 0x00000000);
1434 nv_wo32(disp->mem, 0x1034, 0x00000000);
Ben Skeggs37b034a2011-07-08 14:43:19 +10001435 nv_wo32(disp->mem, 0x0008, NvEvoVRAM);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001436 nv_wo32(disp->mem, 0x000c, (0x1020 << 9) | 0x00000001);
1437
Ben Skeggsc0cc92a2011-07-06 11:40:45 +10001438 nv_wo32(disp->mem, 0x1040, 0x00000009);
1439 nv_wo32(disp->mem, 0x1044, 0x00000000);
1440 nv_wo32(disp->mem, 0x1048, (dev_priv->vram_size - 1) >> 8);
1441 nv_wo32(disp->mem, 0x104c, 0x00000000);
1442 nv_wo32(disp->mem, 0x1050, 0x00000000);
1443 nv_wo32(disp->mem, 0x1054, 0x00000000);
1444 nv_wo32(disp->mem, 0x0010, NvEvoVRAM_LP);
1445 nv_wo32(disp->mem, 0x0014, (0x1040 << 9) | 0x00000001);
1446
1447 nv_wo32(disp->mem, 0x1060, 0x0fe00009);
1448 nv_wo32(disp->mem, 0x1064, 0x00000000);
1449 nv_wo32(disp->mem, 0x1068, (dev_priv->vram_size - 1) >> 8);
1450 nv_wo32(disp->mem, 0x106c, 0x00000000);
1451 nv_wo32(disp->mem, 0x1070, 0x00000000);
1452 nv_wo32(disp->mem, 0x1074, 0x00000000);
1453 nv_wo32(disp->mem, 0x0018, NvEvoFB32);
1454 nv_wo32(disp->mem, 0x001c, (0x1060 << 9) | 0x00000001);
1455
Ben Skeggsefd272a2011-07-05 11:58:58 +10001456 pinstmem->flush(dev);
1457
Ben Skeggs51beb422011-07-05 10:33:08 +10001458 /* push buffers for evo channels */
1459 disp->evo[0].ptr =
1460 pci_alloc_consistent(pdev, PAGE_SIZE, &disp->evo[0].handle);
1461 if (!disp->evo[0].ptr) {
1462 ret = -ENOMEM;
1463 goto out;
1464 }
1465
Ben Skeggs26f6d882011-07-04 16:25:18 +10001466 ret = nvd0_display_init(dev);
1467 if (ret)
1468 goto out;
1469
1470out:
1471 if (ret)
1472 nvd0_display_destroy(dev);
1473 return ret;
1474}