blob: 20072fb784a50051cc34babb74ad597516f3c458 [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
110nvd0_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool on, bool update)
111{
112 struct drm_device *dev = nv_crtc->base.dev;
113 u32 *push, mode;
114
115 mode = 0x00000000;
116 if (on) {
117 /* 0x11: 6bpc dynamic 2x2
118 * 0x13: 8bpc dynamic 2x2
119 * 0x19: 6bpc static 2x2
120 * 0x1b: 8bpc static 2x2
121 * 0x21: 6bpc temporal
122 * 0x23: 8bpc temporal
123 */
124 mode = 0x00000011;
125 }
126
127 push = evo_wait(dev, 0, 4);
128 if (push) {
129 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x300), 1);
130 evo_data(push, mode);
131 if (update) {
132 evo_mthd(push, 0x0080, 1);
133 evo_data(push, 0x00000000);
134 }
135 evo_kick(push, dev, 0);
136 }
137
138 return 0;
139}
140
141static int
142nvd0_crtc_set_scale(struct nouveau_crtc *nv_crtc, int type, bool update)
143{
144 struct drm_display_mode *mode = &nv_crtc->base.mode;
145 struct drm_device *dev = nv_crtc->base.dev;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000146 struct nouveau_connector *nv_connector;
147 u32 *push, outX, outY;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000148
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000149 outX = mode->hdisplay;
150 outY = mode->vdisplay;
151
152 nv_connector = nouveau_crtc_connector_get(nv_crtc);
153 if (nv_connector && nv_connector->native_mode) {
154 struct drm_display_mode *native = nv_connector->native_mode;
155 u32 xratio = (native->hdisplay << 19) / mode->hdisplay;
156 u32 yratio = (native->vdisplay << 19) / mode->vdisplay;
157
158 switch (type) {
159 case DRM_MODE_SCALE_ASPECT:
160 if (xratio > yratio) {
161 outX = (mode->hdisplay * yratio) >> 19;
162 outY = (mode->vdisplay * yratio) >> 19;
163 } else {
164 outX = (mode->hdisplay * xratio) >> 19;
165 outY = (mode->vdisplay * xratio) >> 19;
166 }
167 break;
168 case DRM_MODE_SCALE_FULLSCREEN:
169 outX = native->hdisplay;
170 outY = native->vdisplay;
171 break;
172 default:
173 break;
174 }
175 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000176
177 push = evo_wait(dev, 0, 16);
178 if (push) {
179 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000180 evo_data(push, (outY << 16) | outX);
181 evo_data(push, (outY << 16) | outX);
182 evo_data(push, (outY << 16) | outX);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000183 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
184 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000185 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
186 evo_data(push, (mode->vdisplay << 16) | mode->hdisplay);
187 if (update) {
188 evo_mthd(push, 0x0080, 1);
189 evo_data(push, 0x00000000);
190 }
191 evo_kick(push, dev, 0);
192 }
193
194 return 0;
195}
196
197static int
198nvd0_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
199 int x, int y, bool update)
200{
201 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
202 u32 *push;
203
Ben Skeggs438d99e2011-07-05 16:48:06 +1000204 push = evo_wait(fb->dev, 0, 16);
205 if (push) {
206 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
207 evo_data(push, nvfb->nvbo->bo.offset >> 8);
208 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
209 evo_data(push, (fb->height << 16) | fb->width);
210 evo_data(push, nvfb->r_pitch);
211 evo_data(push, nvfb->r_format);
Ben Skeggsc0cc92a2011-07-06 11:40:45 +1000212 evo_data(push, nvfb->r_dma);
Ben Skeggsc6f2f712011-07-08 12:11:58 +1000213 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
214 evo_data(push, (y << 16) | x);
Ben Skeggsa46232e2011-07-07 15:23:48 +1000215 if (update) {
216 evo_mthd(push, 0x0080, 1);
217 evo_data(push, 0x00000000);
218 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000219 evo_kick(push, fb->dev, 0);
220 }
221
Ben Skeggsc0cc92a2011-07-06 11:40:45 +1000222 nv_crtc->fb.tile_flags = nvfb->r_dma;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000223 return 0;
224}
225
226static void
227nvd0_crtc_cursor_show(struct nouveau_crtc *nv_crtc, bool show, bool update)
228{
229 struct drm_device *dev = nv_crtc->base.dev;
230 u32 *push = evo_wait(dev, 0, 16);
231 if (push) {
232 if (show) {
233 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
234 evo_data(push, 0x85000000);
235 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
236 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
Ben Skeggs37b034a2011-07-08 14:43:19 +1000237 evo_data(push, NvEvoVRAM);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000238 } else {
239 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
240 evo_data(push, 0x05000000);
241 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
242 evo_data(push, 0x00000000);
243 }
244
245 if (update) {
246 evo_mthd(push, 0x0080, 1);
247 evo_data(push, 0x00000000);
248 }
249
250 evo_kick(push, dev, 0);
251 }
252}
253
254static void
255nvd0_crtc_dpms(struct drm_crtc *crtc, int mode)
256{
257}
258
259static void
260nvd0_crtc_prepare(struct drm_crtc *crtc)
261{
262 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
263 u32 *push;
264
265 push = evo_wait(crtc->dev, 0, 2);
266 if (push) {
267 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
268 evo_data(push, 0x00000000);
269 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
270 evo_data(push, 0x03000000);
271 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
272 evo_data(push, 0x00000000);
273 evo_kick(push, crtc->dev, 0);
274 }
275
276 nvd0_crtc_cursor_show(nv_crtc, false, false);
277}
278
279static void
280nvd0_crtc_commit(struct drm_crtc *crtc)
281{
282 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
283 u32 *push;
284
285 push = evo_wait(crtc->dev, 0, 32);
286 if (push) {
287 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
288 evo_data(push, nv_crtc->fb.tile_flags);
289 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
290 evo_data(push, 0x83000000);
291 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
292 evo_data(push, 0x00000000);
293 evo_data(push, 0x00000000);
294 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
Ben Skeggs37b034a2011-07-08 14:43:19 +1000295 evo_data(push, NvEvoVRAM);
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +1000296 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
297 evo_data(push, 0xffffff00);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000298 evo_kick(push, crtc->dev, 0);
299 }
300
301 nvd0_crtc_cursor_show(nv_crtc, nv_crtc->cursor.visible, true);
302}
303
304static bool
305nvd0_crtc_mode_fixup(struct drm_crtc *crtc, struct drm_display_mode *mode,
306 struct drm_display_mode *adjusted_mode)
307{
308 return true;
309}
310
311static int
312nvd0_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
313{
314 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->fb);
315 int ret;
316
317 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
318 if (ret)
319 return ret;
320
321 if (old_fb) {
322 nvfb = nouveau_framebuffer(old_fb);
323 nouveau_bo_unpin(nvfb->nvbo);
324 }
325
326 return 0;
327}
328
329static int
330nvd0_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
331 struct drm_display_mode *mode, int x, int y,
332 struct drm_framebuffer *old_fb)
333{
334 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
335 struct nouveau_connector *nv_connector;
336 u32 htotal = mode->htotal;
337 u32 vtotal = mode->vtotal;
338 u32 hsyncw = mode->hsync_end - mode->hsync_start - 1;
339 u32 vsyncw = mode->vsync_end - mode->vsync_start - 1;
340 u32 hfrntp = mode->hsync_start - mode->hdisplay;
341 u32 vfrntp = mode->vsync_start - mode->vdisplay;
342 u32 hbackp = mode->htotal - mode->hsync_end;
343 u32 vbackp = mode->vtotal - mode->vsync_end;
344 u32 hss2be = hsyncw + hbackp;
345 u32 vss2be = vsyncw + vbackp;
346 u32 hss2de = htotal - hfrntp;
347 u32 vss2de = vtotal - vfrntp;
Ben Skeggs629c1b92011-07-08 09:43:20 +1000348 u32 syncs, *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000349 int ret;
350
Ben Skeggs629c1b92011-07-08 09:43:20 +1000351 syncs = 0x00000001;
352 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
353 syncs |= 0x00000008;
354 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
355 syncs |= 0x00000010;
356
Ben Skeggs438d99e2011-07-05 16:48:06 +1000357 ret = nvd0_crtc_swap_fbs(crtc, old_fb);
358 if (ret)
359 return ret;
360
361 push = evo_wait(crtc->dev, 0, 64);
362 if (push) {
363 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 5);
Ben Skeggs629c1b92011-07-08 09:43:20 +1000364 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000365 evo_data(push, (vtotal << 16) | htotal);
366 evo_data(push, (vsyncw << 16) | hsyncw);
367 evo_data(push, (vss2be << 16) | hss2be);
368 evo_data(push, (vss2de << 16) | hss2de);
369 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
370 evo_data(push, 0x00000000); /* ??? */
371 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
372 evo_data(push, mode->clock * 1000);
373 evo_data(push, 0x00200000); /* ??? */
374 evo_data(push, mode->clock * 1000);
Ben Skeggs629c1b92011-07-08 09:43:20 +1000375 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 1);
376 evo_data(push, syncs);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000377 evo_kick(push, crtc->dev, 0);
378 }
379
380 nv_connector = nouveau_crtc_connector_get(nv_crtc);
381 nvd0_crtc_set_dither(nv_crtc, nv_connector->use_dithering, false);
382 nvd0_crtc_set_scale(nv_crtc, nv_connector->scaling_mode, false);
383 nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, false);
384 return 0;
385}
386
387static int
388nvd0_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
389 struct drm_framebuffer *old_fb)
390{
391 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
392 int ret;
393
394 ret = nvd0_crtc_swap_fbs(crtc, old_fb);
395 if (ret)
396 return ret;
397
398 nvd0_crtc_set_image(nv_crtc, crtc->fb, x, y, true);
399 return 0;
400}
401
402static int
403nvd0_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
404 struct drm_framebuffer *fb, int x, int y,
405 enum mode_set_atomic state)
406{
407 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
408 nvd0_crtc_set_image(nv_crtc, fb, x, y, true);
409 return 0;
410}
411
412static void
413nvd0_crtc_lut_load(struct drm_crtc *crtc)
414{
415 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
416 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
417 int i;
418
419 for (i = 0; i < 256; i++) {
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +1000420 writew(0x6000 + (nv_crtc->lut.r[i] >> 2), lut + (i * 0x20) + 0);
421 writew(0x6000 + (nv_crtc->lut.g[i] >> 2), lut + (i * 0x20) + 2);
422 writew(0x6000 + (nv_crtc->lut.b[i] >> 2), lut + (i * 0x20) + 4);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000423 }
424}
425
426static int
427nvd0_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
428 uint32_t handle, uint32_t width, uint32_t height)
429{
430 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
431 struct drm_device *dev = crtc->dev;
432 struct drm_gem_object *gem;
433 struct nouveau_bo *nvbo;
434 bool visible = (handle != 0);
435 int i, ret = 0;
436
437 if (visible) {
438 if (width != 64 || height != 64)
439 return -EINVAL;
440
441 gem = drm_gem_object_lookup(dev, file_priv, handle);
442 if (unlikely(!gem))
443 return -ENOENT;
444 nvbo = nouveau_gem_object(gem);
445
446 ret = nouveau_bo_map(nvbo);
447 if (ret == 0) {
448 for (i = 0; i < 64 * 64; i++) {
449 u32 v = nouveau_bo_rd32(nvbo, i);
450 nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v);
451 }
452 nouveau_bo_unmap(nvbo);
453 }
454
455 drm_gem_object_unreference_unlocked(gem);
456 }
457
458 if (visible != nv_crtc->cursor.visible) {
459 nvd0_crtc_cursor_show(nv_crtc, visible, true);
460 nv_crtc->cursor.visible = visible;
461 }
462
463 return ret;
464}
465
466static int
467nvd0_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
468{
469 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
470 const u32 data = (y << 16) | x;
471
472 nv_wr32(crtc->dev, 0x64d084 + (nv_crtc->index * 0x1000), data);
473 nv_wr32(crtc->dev, 0x64d080 + (nv_crtc->index * 0x1000), 0x00000000);
474 return 0;
475}
476
477static void
478nvd0_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
479 uint32_t start, uint32_t size)
480{
481 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
482 u32 end = max(start + size, (u32)256);
483 u32 i;
484
485 for (i = start; i < end; i++) {
486 nv_crtc->lut.r[i] = r[i];
487 nv_crtc->lut.g[i] = g[i];
488 nv_crtc->lut.b[i] = b[i];
489 }
490
491 nvd0_crtc_lut_load(crtc);
492}
493
494static void
495nvd0_crtc_destroy(struct drm_crtc *crtc)
496{
497 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
498 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
499 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
500 nouveau_bo_unmap(nv_crtc->lut.nvbo);
501 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
502 drm_crtc_cleanup(crtc);
503 kfree(crtc);
504}
505
506static const struct drm_crtc_helper_funcs nvd0_crtc_hfunc = {
507 .dpms = nvd0_crtc_dpms,
508 .prepare = nvd0_crtc_prepare,
509 .commit = nvd0_crtc_commit,
510 .mode_fixup = nvd0_crtc_mode_fixup,
511 .mode_set = nvd0_crtc_mode_set,
512 .mode_set_base = nvd0_crtc_mode_set_base,
513 .mode_set_base_atomic = nvd0_crtc_mode_set_base_atomic,
514 .load_lut = nvd0_crtc_lut_load,
515};
516
517static const struct drm_crtc_funcs nvd0_crtc_func = {
518 .cursor_set = nvd0_crtc_cursor_set,
519 .cursor_move = nvd0_crtc_cursor_move,
520 .gamma_set = nvd0_crtc_gamma_set,
521 .set_config = drm_crtc_helper_set_config,
522 .destroy = nvd0_crtc_destroy,
523};
524
Ben Skeggsc20ab3e2011-08-25 14:09:43 +1000525static void
526nvd0_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
527{
528}
529
530static void
531nvd0_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
532{
533}
534
Ben Skeggs438d99e2011-07-05 16:48:06 +1000535static int
536nvd0_crtc_create(struct drm_device *dev, int index)
537{
538 struct nouveau_crtc *nv_crtc;
539 struct drm_crtc *crtc;
540 int ret, i;
541
542 nv_crtc = kzalloc(sizeof(*nv_crtc), GFP_KERNEL);
543 if (!nv_crtc)
544 return -ENOMEM;
545
546 nv_crtc->index = index;
547 nv_crtc->set_dither = nvd0_crtc_set_dither;
548 nv_crtc->set_scale = nvd0_crtc_set_scale;
Ben Skeggsc20ab3e2011-08-25 14:09:43 +1000549 nv_crtc->cursor.set_offset = nvd0_cursor_set_offset;
550 nv_crtc->cursor.set_pos = nvd0_cursor_set_pos;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000551 for (i = 0; i < 256; i++) {
552 nv_crtc->lut.r[i] = i << 8;
553 nv_crtc->lut.g[i] = i << 8;
554 nv_crtc->lut.b[i] = i << 8;
555 }
556
557 crtc = &nv_crtc->base;
558 drm_crtc_init(dev, crtc, &nvd0_crtc_func);
559 drm_crtc_helper_add(crtc, &nvd0_crtc_hfunc);
560 drm_mode_crtc_set_gamma_size(crtc, 256);
561
562 ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM,
563 0, 0x0000, &nv_crtc->cursor.nvbo);
564 if (!ret) {
565 ret = nouveau_bo_pin(nv_crtc->cursor.nvbo, TTM_PL_FLAG_VRAM);
566 if (!ret)
567 ret = nouveau_bo_map(nv_crtc->cursor.nvbo);
568 if (ret)
569 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
570 }
571
572 if (ret)
573 goto out;
574
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +1000575 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000576 0, 0x0000, &nv_crtc->lut.nvbo);
577 if (!ret) {
578 ret = nouveau_bo_pin(nv_crtc->lut.nvbo, TTM_PL_FLAG_VRAM);
579 if (!ret)
580 ret = nouveau_bo_map(nv_crtc->lut.nvbo);
581 if (ret)
582 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
583 }
584
585 if (ret)
586 goto out;
587
588 nvd0_crtc_lut_load(crtc);
589
590out:
591 if (ret)
592 nvd0_crtc_destroy(crtc);
593 return ret;
594}
595
596/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +1000597 * DAC
598 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000599static void
600nvd0_dac_dpms(struct drm_encoder *encoder, int mode)
601{
602 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
603 struct drm_device *dev = encoder->dev;
604 int or = nv_encoder->or;
605 u32 dpms_ctrl;
606
607 dpms_ctrl = 0x80000000;
608 if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF)
609 dpms_ctrl |= 0x00000001;
610 if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF)
611 dpms_ctrl |= 0x00000004;
612
613 nv_wait(dev, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
614 nv_mask(dev, 0x61a004 + (or * 0x0800), 0xc000007f, dpms_ctrl);
615 nv_wait(dev, 0x61a004 + (or * 0x0800), 0x80000000, 0x00000000);
616}
617
618static bool
619nvd0_dac_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
620 struct drm_display_mode *adjusted_mode)
621{
622 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
623 struct nouveau_connector *nv_connector;
624
625 nv_connector = nouveau_encoder_connector_get(nv_encoder);
626 if (nv_connector && nv_connector->native_mode) {
627 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
628 int id = adjusted_mode->base.id;
629 *adjusted_mode = *nv_connector->native_mode;
630 adjusted_mode->base.id = id;
631 }
632 }
633
634 return true;
635}
636
637static void
638nvd0_dac_prepare(struct drm_encoder *encoder)
639{
640}
641
642static void
643nvd0_dac_commit(struct drm_encoder *encoder)
644{
645}
646
647static void
648nvd0_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
649 struct drm_display_mode *adjusted_mode)
650{
651 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
652 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
653 u32 *push;
654
655 nvd0_dac_dpms(encoder, DRM_MODE_DPMS_ON);
656
Ben Skeggsff8ff502011-07-08 11:53:37 +1000657 push = evo_wait(encoder->dev, 0, 4);
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000658 if (push) {
Ben Skeggsff8ff502011-07-08 11:53:37 +1000659 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x20), 2);
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000660 evo_data(push, 1 << nv_crtc->index);
Ben Skeggsff8ff502011-07-08 11:53:37 +1000661 evo_data(push, 0x00ff);
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000662 evo_kick(push, encoder->dev, 0);
663 }
664
665 nv_encoder->crtc = encoder->crtc;
666}
667
668static void
669nvd0_dac_disconnect(struct drm_encoder *encoder)
670{
671 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
672 struct drm_device *dev = encoder->dev;
673 u32 *push;
674
675 if (nv_encoder->crtc) {
676 nvd0_crtc_prepare(nv_encoder->crtc);
677
678 push = evo_wait(dev, 0, 4);
679 if (push) {
680 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x20), 1);
681 evo_data(push, 0x00000000);
682 evo_mthd(push, 0x0080, 1);
683 evo_data(push, 0x00000000);
684 evo_kick(push, dev, 0);
685 }
686
687 nv_encoder->crtc = NULL;
688 }
689}
690
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +1000691static enum drm_connector_status
692nvd0_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
693{
Ben Skeggsb6819932011-07-08 11:14:50 +1000694 enum drm_connector_status status = connector_status_disconnected;
695 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
696 struct drm_device *dev = encoder->dev;
697 int or = nv_encoder->or;
698 u32 load;
699
700 nv_wr32(dev, 0x61a00c + (or * 0x800), 0x00100000);
701 udelay(9500);
702 nv_wr32(dev, 0x61a00c + (or * 0x800), 0x80000000);
703
704 load = nv_rd32(dev, 0x61a00c + (or * 0x800));
705 if ((load & 0x38000000) == 0x38000000)
706 status = connector_status_connected;
707
708 nv_wr32(dev, 0x61a00c + (or * 0x800), 0x00000000);
709 return status;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +1000710}
711
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000712static void
713nvd0_dac_destroy(struct drm_encoder *encoder)
714{
715 drm_encoder_cleanup(encoder);
716 kfree(encoder);
717}
718
719static const struct drm_encoder_helper_funcs nvd0_dac_hfunc = {
720 .dpms = nvd0_dac_dpms,
721 .mode_fixup = nvd0_dac_mode_fixup,
722 .prepare = nvd0_dac_prepare,
723 .commit = nvd0_dac_commit,
724 .mode_set = nvd0_dac_mode_set,
725 .disable = nvd0_dac_disconnect,
726 .get_crtc = nvd0_display_crtc_get,
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +1000727 .detect = nvd0_dac_detect
Ben Skeggs8eaa9662011-07-06 15:25:47 +1000728};
729
730static const struct drm_encoder_funcs nvd0_dac_func = {
731 .destroy = nvd0_dac_destroy,
732};
733
734static int
735nvd0_dac_create(struct drm_connector *connector, struct dcb_entry *dcbe)
736{
737 struct drm_device *dev = connector->dev;
738 struct nouveau_encoder *nv_encoder;
739 struct drm_encoder *encoder;
740
741 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
742 if (!nv_encoder)
743 return -ENOMEM;
744 nv_encoder->dcb = dcbe;
745 nv_encoder->or = ffs(dcbe->or) - 1;
746
747 encoder = to_drm_encoder(nv_encoder);
748 encoder->possible_crtcs = dcbe->heads;
749 encoder->possible_clones = 0;
750 drm_encoder_init(dev, encoder, &nvd0_dac_func, DRM_MODE_ENCODER_DAC);
751 drm_encoder_helper_add(encoder, &nvd0_dac_hfunc);
752
753 drm_mode_connector_attach_encoder(connector, encoder);
754 return 0;
755}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000756
757/******************************************************************************
758 * SOR
759 *****************************************************************************/
Ben Skeggs83fc0832011-07-05 13:08:40 +1000760static void
761nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
762{
763 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
764 struct drm_device *dev = encoder->dev;
765 struct drm_encoder *partner;
766 int or = nv_encoder->or;
767 u32 dpms_ctrl;
768
769 nv_encoder->last_dpms = mode;
770
771 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
772 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
773
774 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
775 continue;
776
777 if (nv_partner != nv_encoder &&
778 nv_partner->dcb->or == nv_encoder->or) {
779 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
780 return;
781 break;
782 }
783 }
784
785 dpms_ctrl = (mode == DRM_MODE_DPMS_ON);
786 dpms_ctrl |= 0x80000000;
787
788 nv_wait(dev, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
789 nv_mask(dev, 0x61c004 + (or * 0x0800), 0x80000001, dpms_ctrl);
790 nv_wait(dev, 0x61c004 + (or * 0x0800), 0x80000000, 0x00000000);
791 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
792}
793
794static bool
795nvd0_sor_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode,
796 struct drm_display_mode *adjusted_mode)
797{
798 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
799 struct nouveau_connector *nv_connector;
800
801 nv_connector = nouveau_encoder_connector_get(nv_encoder);
802 if (nv_connector && nv_connector->native_mode) {
803 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
804 int id = adjusted_mode->base.id;
805 *adjusted_mode = *nv_connector->native_mode;
806 adjusted_mode->base.id = id;
807 }
808 }
809
810 return true;
811}
812
813static void
814nvd0_sor_prepare(struct drm_encoder *encoder)
815{
816}
817
818static void
819nvd0_sor_commit(struct drm_encoder *encoder)
820{
821}
822
823static void
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000824nvd0_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
825 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +1000826{
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000827 struct drm_nouveau_private *dev_priv = encoder->dev->dev_private;
Ben Skeggs83fc0832011-07-05 13:08:40 +1000828 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
829 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000830 struct nouveau_connector *nv_connector;
831 struct nvbios *bios = &dev_priv->vbios;
Ben Skeggs83fc0832011-07-05 13:08:40 +1000832 u32 mode_ctrl = (1 << nv_crtc->index);
Ben Skeggsff8ff502011-07-08 11:53:37 +1000833 u32 *push, or_config;
Ben Skeggs83fc0832011-07-05 13:08:40 +1000834
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000835 nv_connector = nouveau_encoder_connector_get(nv_encoder);
836 switch (nv_encoder->dcb->type) {
837 case OUTPUT_TMDS:
838 if (nv_encoder->dcb->sorconf.link & 1) {
839 if (mode->clock < 165000)
840 mode_ctrl |= 0x00000100;
841 else
842 mode_ctrl |= 0x00000500;
843 } else {
844 mode_ctrl |= 0x00000200;
845 }
Ben Skeggs83fc0832011-07-05 13:08:40 +1000846
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000847 or_config = (mode_ctrl & 0x00000f00) >> 8;
848 if (mode->clock >= 165000)
849 or_config |= 0x0100;
850 break;
851 case OUTPUT_LVDS:
852 or_config = (mode_ctrl & 0x00000f00) >> 8;
853 if (bios->fp_no_ddc) {
854 if (bios->fp.dual_link)
855 or_config |= 0x0100;
856 if (bios->fp.if_is_24bit)
857 or_config |= 0x0200;
858 } else {
859 if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS_SPWG) {
860 if (((u8 *)nv_connector->edid)[121] == 2)
861 or_config |= 0x0100;
862 } else
863 if (mode->clock >= bios->fp.duallink_transition_clk) {
864 or_config |= 0x0100;
865 }
866
867 if (or_config & 0x0100) {
868 if (bios->fp.strapless_is_24bit & 2)
869 or_config |= 0x0200;
870 } else {
871 if (bios->fp.strapless_is_24bit & 1)
872 or_config |= 0x0200;
873 }
874
875 if (nv_connector->base.display_info.bpc == 8)
876 or_config |= 0x0200;
877
878 }
879 break;
880 default:
881 BUG_ON(1);
882 break;
883 }
Ben Skeggsff8ff502011-07-08 11:53:37 +1000884
Ben Skeggs83fc0832011-07-05 13:08:40 +1000885 nvd0_sor_dpms(encoder, DRM_MODE_DPMS_ON);
886
Ben Skeggsff8ff502011-07-08 11:53:37 +1000887 push = evo_wait(encoder->dev, 0, 4);
Ben Skeggs83fc0832011-07-05 13:08:40 +1000888 if (push) {
Ben Skeggsff8ff502011-07-08 11:53:37 +1000889 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 2);
Ben Skeggs83fc0832011-07-05 13:08:40 +1000890 evo_data(push, mode_ctrl);
Ben Skeggsff8ff502011-07-08 11:53:37 +1000891 evo_data(push, or_config);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000892 evo_kick(push, encoder->dev, 0);
Ben Skeggs83fc0832011-07-05 13:08:40 +1000893 }
894
895 nv_encoder->crtc = encoder->crtc;
896}
897
898static void
899nvd0_sor_disconnect(struct drm_encoder *encoder)
900{
901 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
902 struct drm_device *dev = encoder->dev;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000903 u32 *push;
Ben Skeggs83fc0832011-07-05 13:08:40 +1000904
905 if (nv_encoder->crtc) {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000906 nvd0_crtc_prepare(nv_encoder->crtc);
907
908 push = evo_wait(dev, 0, 4);
Ben Skeggs83fc0832011-07-05 13:08:40 +1000909 if (push) {
910 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
911 evo_data(push, 0x00000000);
912 evo_mthd(push, 0x0080, 1);
913 evo_data(push, 0x00000000);
914 evo_kick(push, dev, 0);
915 }
916
917 nv_encoder->crtc = NULL;
918 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
919 }
920}
921
922static void
923nvd0_sor_destroy(struct drm_encoder *encoder)
924{
925 drm_encoder_cleanup(encoder);
926 kfree(encoder);
927}
928
929static const struct drm_encoder_helper_funcs nvd0_sor_hfunc = {
930 .dpms = nvd0_sor_dpms,
931 .mode_fixup = nvd0_sor_mode_fixup,
932 .prepare = nvd0_sor_prepare,
933 .commit = nvd0_sor_commit,
934 .mode_set = nvd0_sor_mode_set,
935 .disable = nvd0_sor_disconnect,
936 .get_crtc = nvd0_display_crtc_get,
937};
938
939static const struct drm_encoder_funcs nvd0_sor_func = {
940 .destroy = nvd0_sor_destroy,
941};
942
943static int
944nvd0_sor_create(struct drm_connector *connector, struct dcb_entry *dcbe)
945{
946 struct drm_device *dev = connector->dev;
947 struct nouveau_encoder *nv_encoder;
948 struct drm_encoder *encoder;
949
950 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
951 if (!nv_encoder)
952 return -ENOMEM;
953 nv_encoder->dcb = dcbe;
954 nv_encoder->or = ffs(dcbe->or) - 1;
955 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
956
957 encoder = to_drm_encoder(nv_encoder);
958 encoder->possible_crtcs = dcbe->heads;
959 encoder->possible_clones = 0;
960 drm_encoder_init(dev, encoder, &nvd0_sor_func, DRM_MODE_ENCODER_TMDS);
961 drm_encoder_helper_add(encoder, &nvd0_sor_hfunc);
962
963 drm_mode_connector_attach_encoder(connector, encoder);
964 return 0;
965}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000966
967/******************************************************************************
968 * IRQ
969 *****************************************************************************/
Ben Skeggs3a89cd02011-07-07 10:47:10 +1000970static struct dcb_entry *
971lookup_dcb(struct drm_device *dev, int id, u32 mc)
972{
973 struct drm_nouveau_private *dev_priv = dev->dev_private;
974 int type, or, i;
975
976 if (id < 4) {
977 type = OUTPUT_ANALOG;
978 or = id;
979 } else {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000980 switch (mc & 0x00000f00) {
981 case 0x00000000: type = OUTPUT_LVDS; break;
982 case 0x00000100: type = OUTPUT_TMDS; break;
983 case 0x00000200: type = OUTPUT_TMDS; break;
984 case 0x00000500: type = OUTPUT_TMDS; break;
985 default:
Ben Skeggsee417792011-07-08 14:34:45 +1000986 NV_ERROR(dev, "PDISP: unknown SOR mc 0x%08x\n", mc);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +1000987 return NULL;
988 }
989
990 or = id - 4;
Ben Skeggs3a89cd02011-07-07 10:47:10 +1000991 }
992
993 for (i = 0; i < dev_priv->vbios.dcb.entries; i++) {
994 struct dcb_entry *dcb = &dev_priv->vbios.dcb.entry[i];
995 if (dcb->type == type && (dcb->or & (1 << or)))
996 return dcb;
997 }
998
Ben Skeggsee417792011-07-08 14:34:45 +1000999 NV_ERROR(dev, "PDISP: DCB for %d/0x%08x not found\n", id, mc);
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001000 return NULL;
1001}
1002
Ben Skeggs46005222011-07-05 11:01:13 +10001003static void
Ben Skeggs37b034a2011-07-08 14:43:19 +10001004nvd0_display_unk1_handler(struct drm_device *dev, u32 crtc, u32 mask)
Ben Skeggs270a5742011-07-05 14:16:05 +10001005{
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001006 struct dcb_entry *dcb;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001007 int i;
1008
Ben Skeggsee417792011-07-08 14:34:45 +10001009 for (i = 0; mask && i < 8; i++) {
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001010 u32 mcc = nv_rd32(dev, 0x640180 + (i * 0x20));
Ben Skeggsee417792011-07-08 14:34:45 +10001011 if (!(mcc & (1 << crtc)))
1012 continue;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001013
Ben Skeggsee417792011-07-08 14:34:45 +10001014 dcb = lookup_dcb(dev, i, mcc);
1015 if (!dcb)
1016 continue;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001017
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001018 nouveau_bios_run_display_table(dev, 0x0000, -1, dcb, crtc);
Ben Skeggsee417792011-07-08 14:34:45 +10001019 }
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001020
Ben Skeggs270a5742011-07-05 14:16:05 +10001021 nv_wr32(dev, 0x6101d4, 0x00000000);
1022 nv_wr32(dev, 0x6109d4, 0x00000000);
1023 nv_wr32(dev, 0x6101d0, 0x80000000);
1024}
1025
1026static void
Ben Skeggs37b034a2011-07-08 14:43:19 +10001027nvd0_display_unk2_handler(struct drm_device *dev, u32 crtc, u32 mask)
Ben Skeggs270a5742011-07-05 14:16:05 +10001028{
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001029 struct dcb_entry *dcb;
Ben Skeggs37b034a2011-07-08 14:43:19 +10001030 u32 or, tmp, pclk;
Ben Skeggsee417792011-07-08 14:34:45 +10001031 int i;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001032
Ben Skeggsee417792011-07-08 14:34:45 +10001033 for (i = 0; mask && i < 8; i++) {
1034 u32 mcc = nv_rd32(dev, 0x640180 + (i * 0x20));
1035 if (!(mcc & (1 << crtc)))
1036 continue;
1037
1038 dcb = lookup_dcb(dev, i, mcc);
1039 if (!dcb)
1040 continue;
1041
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001042 nouveau_bios_run_display_table(dev, 0x0000, -2, dcb, crtc);
Ben Skeggsee417792011-07-08 14:34:45 +10001043 }
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001044
Ben Skeggsee417792011-07-08 14:34:45 +10001045 pclk = nv_rd32(dev, 0x660450 + (crtc * 0x300)) / 1000;
1046 if (mask & 0x00010000) {
1047 nv50_crtc_set_clock(dev, crtc, pclk);
1048 }
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001049
Ben Skeggsee417792011-07-08 14:34:45 +10001050 for (i = 0; mask && i < 8; i++) {
1051 u32 mcp = nv_rd32(dev, 0x660180 + (i * 0x20));
1052 u32 cfg = nv_rd32(dev, 0x660184 + (i * 0x20));
1053 if (!(mcp & (1 << crtc)))
1054 continue;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001055
Ben Skeggsee417792011-07-08 14:34:45 +10001056 dcb = lookup_dcb(dev, i, mcp);
1057 if (!dcb)
1058 continue;
1059 or = ffs(dcb->or) - 1;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001060
Ben Skeggsee417792011-07-08 14:34:45 +10001061 nouveau_bios_run_display_table(dev, cfg, pclk, dcb, crtc);
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001062
Ben Skeggsee417792011-07-08 14:34:45 +10001063 nv_wr32(dev, 0x612200 + (crtc * 0x800), 0x00000000);
1064 switch (dcb->type) {
1065 case OUTPUT_ANALOG:
1066 nv_wr32(dev, 0x612280 + (or * 0x800), 0x00000000);
1067 break;
1068 case OUTPUT_TMDS:
1069 case OUTPUT_LVDS:
1070 if (cfg & 0x00000100)
1071 tmp = 0x00000101;
1072 else
1073 tmp = 0x00000000;
1074
1075 nv_mask(dev, 0x612300 + (or * 0x800), 0x00000707, tmp);
1076 break;
1077 default:
1078 break;
1079 }
1080
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001081 break;
1082 }
1083
Ben Skeggs270a5742011-07-05 14:16:05 +10001084 nv_wr32(dev, 0x6101d4, 0x00000000);
1085 nv_wr32(dev, 0x6109d4, 0x00000000);
1086 nv_wr32(dev, 0x6101d0, 0x80000000);
1087}
1088
1089static void
Ben Skeggs37b034a2011-07-08 14:43:19 +10001090nvd0_display_unk4_handler(struct drm_device *dev, u32 crtc, u32 mask)
Ben Skeggs270a5742011-07-05 14:16:05 +10001091{
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001092 struct dcb_entry *dcb;
Ben Skeggsee417792011-07-08 14:34:45 +10001093 int pclk, i;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001094
Ben Skeggsee417792011-07-08 14:34:45 +10001095 pclk = nv_rd32(dev, 0x660450 + (crtc * 0x300)) / 1000;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001096
Ben Skeggsee417792011-07-08 14:34:45 +10001097 for (i = 0; mask && i < 8; i++) {
1098 u32 mcp = nv_rd32(dev, 0x660180 + (i * 0x20));
1099 u32 cfg = nv_rd32(dev, 0x660184 + (i * 0x20));
1100 if (!(mcp & (1 << crtc)))
1101 continue;
Ben Skeggs3a89cd02011-07-07 10:47:10 +10001102
Ben Skeggsee417792011-07-08 14:34:45 +10001103 dcb = lookup_dcb(dev, i, mcp);
1104 if (!dcb)
1105 continue;
1106
1107 nouveau_bios_run_display_table(dev, cfg, -pclk, dcb, crtc);
1108 }
1109
Ben Skeggs270a5742011-07-05 14:16:05 +10001110 nv_wr32(dev, 0x6101d4, 0x00000000);
1111 nv_wr32(dev, 0x6109d4, 0x00000000);
1112 nv_wr32(dev, 0x6101d0, 0x80000000);
1113}
1114
1115static void
Ben Skeggsf20ce962011-07-08 13:17:01 +10001116nvd0_display_bh(unsigned long data)
1117{
1118 struct drm_device *dev = (struct drm_device *)data;
1119 struct nvd0_display *disp = nvd0_display(dev);
Ben Skeggs37b034a2011-07-08 14:43:19 +10001120 u32 mask, crtc;
1121 int i;
1122
1123 if (drm_debug & (DRM_UT_DRIVER | DRM_UT_KMS)) {
1124 NV_INFO(dev, "PDISP: modeset req %d\n", disp->modeset);
1125 NV_INFO(dev, " STAT: 0x%08x 0x%08x 0x%08x\n",
1126 nv_rd32(dev, 0x6101d0),
1127 nv_rd32(dev, 0x6101d4), nv_rd32(dev, 0x6109d4));
1128 for (i = 0; i < 8; i++) {
1129 NV_INFO(dev, " %s%d: 0x%08x 0x%08x\n",
1130 i < 4 ? "DAC" : "SOR", i,
1131 nv_rd32(dev, 0x640180 + (i * 0x20)),
1132 nv_rd32(dev, 0x660180 + (i * 0x20)));
1133 }
1134 }
1135
1136 mask = nv_rd32(dev, 0x6101d4);
1137 crtc = 0;
1138 if (!mask) {
1139 mask = nv_rd32(dev, 0x6109d4);
1140 crtc = 1;
1141 }
Ben Skeggsf20ce962011-07-08 13:17:01 +10001142
Ben Skeggsee417792011-07-08 14:34:45 +10001143 if (disp->modeset & 0x00000001)
Ben Skeggs37b034a2011-07-08 14:43:19 +10001144 nvd0_display_unk1_handler(dev, crtc, mask);
Ben Skeggsee417792011-07-08 14:34:45 +10001145 if (disp->modeset & 0x00000002)
Ben Skeggs37b034a2011-07-08 14:43:19 +10001146 nvd0_display_unk2_handler(dev, crtc, mask);
Ben Skeggsee417792011-07-08 14:34:45 +10001147 if (disp->modeset & 0x00000004)
Ben Skeggs37b034a2011-07-08 14:43:19 +10001148 nvd0_display_unk4_handler(dev, crtc, mask);
Ben Skeggsf20ce962011-07-08 13:17:01 +10001149}
1150
1151static void
Ben Skeggs46005222011-07-05 11:01:13 +10001152nvd0_display_intr(struct drm_device *dev)
1153{
Ben Skeggsf20ce962011-07-08 13:17:01 +10001154 struct nvd0_display *disp = nvd0_display(dev);
Ben Skeggs46005222011-07-05 11:01:13 +10001155 u32 intr = nv_rd32(dev, 0x610088);
1156
1157 if (intr & 0x00000002) {
1158 u32 stat = nv_rd32(dev, 0x61009c);
1159 int chid = ffs(stat) - 1;
1160 if (chid >= 0) {
1161 u32 mthd = nv_rd32(dev, 0x6101f0 + (chid * 12));
1162 u32 data = nv_rd32(dev, 0x6101f4 + (chid * 12));
1163 u32 unkn = nv_rd32(dev, 0x6101f8 + (chid * 12));
1164
1165 NV_INFO(dev, "EvoCh: chid %d mthd 0x%04x data 0x%08x "
1166 "0x%08x 0x%08x\n",
1167 chid, (mthd & 0x0000ffc), data, mthd, unkn);
1168 nv_wr32(dev, 0x61009c, (1 << chid));
1169 nv_wr32(dev, 0x6101f0 + (chid * 12), 0x90000000);
1170 }
1171
1172 intr &= ~0x00000002;
1173 }
1174
Ben Skeggs270a5742011-07-05 14:16:05 +10001175 if (intr & 0x00100000) {
1176 u32 stat = nv_rd32(dev, 0x6100ac);
1177
1178 if (stat & 0x00000007) {
Ben Skeggsee417792011-07-08 14:34:45 +10001179 disp->modeset = stat;
Ben Skeggsf20ce962011-07-08 13:17:01 +10001180 tasklet_schedule(&disp->tasklet);
Ben Skeggs270a5742011-07-05 14:16:05 +10001181
Ben Skeggsf20ce962011-07-08 13:17:01 +10001182 nv_wr32(dev, 0x6100ac, (stat & 0x00000007));
Ben Skeggs270a5742011-07-05 14:16:05 +10001183 stat &= ~0x00000007;
1184 }
1185
1186 if (stat) {
1187 NV_INFO(dev, "PDISP: unknown intr24 0x%08x\n", stat);
1188 nv_wr32(dev, 0x6100ac, stat);
1189 }
1190
1191 intr &= ~0x00100000;
1192 }
1193
Ben Skeggs46005222011-07-05 11:01:13 +10001194 if (intr & 0x01000000) {
1195 u32 stat = nv_rd32(dev, 0x6100bc);
1196 nv_wr32(dev, 0x6100bc, stat);
1197 intr &= ~0x01000000;
1198 }
1199
1200 if (intr & 0x02000000) {
1201 u32 stat = nv_rd32(dev, 0x6108bc);
1202 nv_wr32(dev, 0x6108bc, stat);
1203 intr &= ~0x02000000;
1204 }
1205
1206 if (intr)
1207 NV_INFO(dev, "PDISP: unknown intr 0x%08x\n", intr);
1208}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001209
1210/******************************************************************************
1211 * Init
1212 *****************************************************************************/
1213static void
1214nvd0_display_fini(struct drm_device *dev)
1215{
1216 int i;
1217
1218 /* fini cursors */
1219 for (i = 14; i >= 13; i--) {
1220 if (!(nv_rd32(dev, 0x610490 + (i * 0x10)) & 0x00000001))
1221 continue;
1222
1223 nv_mask(dev, 0x610490 + (i * 0x10), 0x00000001, 0x00000000);
1224 nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00000000);
1225 nv_mask(dev, 0x610090, 1 << i, 0x00000000);
1226 nv_mask(dev, 0x6100a0, 1 << i, 0x00000000);
1227 }
1228
1229 /* fini master */
1230 if (nv_rd32(dev, 0x610490) & 0x00000010) {
1231 nv_mask(dev, 0x610490, 0x00000010, 0x00000000);
1232 nv_mask(dev, 0x610490, 0x00000003, 0x00000000);
1233 nv_wait(dev, 0x610490, 0x80000000, 0x00000000);
1234 nv_mask(dev, 0x610090, 0x00000001, 0x00000000);
1235 nv_mask(dev, 0x6100a0, 0x00000001, 0x00000000);
1236 }
1237}
1238
1239int
1240nvd0_display_init(struct drm_device *dev)
1241{
1242 struct nvd0_display *disp = nvd0_display(dev);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001243 u32 *push;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001244 int i;
1245
1246 if (nv_rd32(dev, 0x6100ac) & 0x00000100) {
1247 nv_wr32(dev, 0x6100ac, 0x00000100);
1248 nv_mask(dev, 0x6194e8, 0x00000001, 0x00000000);
1249 if (!nv_wait(dev, 0x6194e8, 0x00000002, 0x00000000)) {
1250 NV_ERROR(dev, "PDISP: 0x6194e8 0x%08x\n",
1251 nv_rd32(dev, 0x6194e8));
1252 return -EBUSY;
1253 }
1254 }
1255
Ben Skeggsa36f04c2011-07-06 14:39:23 +10001256 /* nfi what these are exactly, i do know that SOR_MODE_CTRL won't
1257 * work at all unless you do the SOR part below.
1258 */
1259 for (i = 0; i < 3; i++) {
1260 u32 dac = nv_rd32(dev, 0x61a000 + (i * 0x800));
1261 nv_wr32(dev, 0x6101c0 + (i * 0x800), dac);
1262 }
1263
1264 for (i = 0; i < 4; i++) {
1265 u32 sor = nv_rd32(dev, 0x61c000 + (i * 0x800));
1266 nv_wr32(dev, 0x6301c4 + (i * 0x800), sor);
1267 }
1268
1269 for (i = 0; i < 2; i++) {
1270 u32 crtc0 = nv_rd32(dev, 0x616104 + (i * 0x800));
1271 u32 crtc1 = nv_rd32(dev, 0x616108 + (i * 0x800));
1272 u32 crtc2 = nv_rd32(dev, 0x61610c + (i * 0x800));
1273 nv_wr32(dev, 0x6101b4 + (i * 0x800), crtc0);
1274 nv_wr32(dev, 0x6101b8 + (i * 0x800), crtc1);
1275 nv_wr32(dev, 0x6101bc + (i * 0x800), crtc2);
1276 }
1277
1278 /* point at our hash table / objects, enable interrupts */
Ben Skeggs26f6d882011-07-04 16:25:18 +10001279 nv_wr32(dev, 0x610010, (disp->mem->vinst >> 8) | 9);
Ben Skeggs270a5742011-07-05 14:16:05 +10001280 nv_mask(dev, 0x6100b0, 0x00000307, 0x00000307);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001281
1282 /* init master */
Ben Skeggs51beb422011-07-05 10:33:08 +10001283 nv_wr32(dev, 0x610494, (disp->evo[0].handle >> 8) | 3);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001284 nv_wr32(dev, 0x610498, 0x00010000);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001285 nv_wr32(dev, 0x61049c, 0x00000001);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001286 nv_mask(dev, 0x610490, 0x00000010, 0x00000010);
1287 nv_wr32(dev, 0x640000, 0x00000000);
1288 nv_wr32(dev, 0x610490, 0x01000013);
1289 if (!nv_wait(dev, 0x610490, 0x80000000, 0x00000000)) {
1290 NV_ERROR(dev, "PDISP: master 0x%08x\n",
1291 nv_rd32(dev, 0x610490));
1292 return -EBUSY;
1293 }
1294 nv_mask(dev, 0x610090, 0x00000001, 0x00000001);
1295 nv_mask(dev, 0x6100a0, 0x00000001, 0x00000001);
1296
1297 /* init cursors */
1298 for (i = 13; i <= 14; i++) {
1299 nv_wr32(dev, 0x610490 + (i * 0x10), 0x00000001);
1300 if (!nv_wait(dev, 0x610490 + (i * 0x10), 0x00010000, 0x00010000)) {
1301 NV_ERROR(dev, "PDISP: curs%d 0x%08x\n", i,
1302 nv_rd32(dev, 0x610490 + (i * 0x10)));
1303 return -EBUSY;
1304 }
1305
1306 nv_mask(dev, 0x610090, 1 << i, 1 << i);
1307 nv_mask(dev, 0x6100a0, 1 << i, 1 << i);
1308 }
1309
Ben Skeggsefd272a2011-07-05 11:58:58 +10001310 push = evo_wait(dev, 0, 32);
1311 if (!push)
1312 return -EBUSY;
1313 evo_mthd(push, 0x0088, 1);
Ben Skeggs37b034a2011-07-08 14:43:19 +10001314 evo_data(push, NvEvoSync);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001315 evo_mthd(push, 0x0084, 1);
1316 evo_data(push, 0x00000000);
1317 evo_mthd(push, 0x0084, 1);
1318 evo_data(push, 0x80000000);
1319 evo_mthd(push, 0x008c, 1);
1320 evo_data(push, 0x00000000);
1321 evo_kick(push, dev, 0);
1322
Ben Skeggs26f6d882011-07-04 16:25:18 +10001323 return 0;
1324}
1325
1326void
1327nvd0_display_destroy(struct drm_device *dev)
1328{
1329 struct drm_nouveau_private *dev_priv = dev->dev_private;
1330 struct nvd0_display *disp = nvd0_display(dev);
Ben Skeggs51beb422011-07-05 10:33:08 +10001331 struct pci_dev *pdev = dev->pdev;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001332
1333 nvd0_display_fini(dev);
1334
Ben Skeggs51beb422011-07-05 10:33:08 +10001335 pci_free_consistent(pdev, PAGE_SIZE, disp->evo[0].ptr, disp->evo[0].handle);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001336 nouveau_gpuobj_ref(NULL, &disp->mem);
Ben Skeggs46005222011-07-05 11:01:13 +10001337 nouveau_irq_unregister(dev, 26);
Ben Skeggs51beb422011-07-05 10:33:08 +10001338
1339 dev_priv->engine.display.priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001340 kfree(disp);
1341}
1342
1343int
1344nvd0_display_create(struct drm_device *dev)
1345{
1346 struct drm_nouveau_private *dev_priv = dev->dev_private;
Ben Skeggsefd272a2011-07-05 11:58:58 +10001347 struct nouveau_instmem_engine *pinstmem = &dev_priv->engine.instmem;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001348 struct dcb_table *dcb = &dev_priv->vbios.dcb;
1349 struct drm_connector *connector, *tmp;
Ben Skeggs51beb422011-07-05 10:33:08 +10001350 struct pci_dev *pdev = dev->pdev;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001351 struct nvd0_display *disp;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001352 struct dcb_entry *dcbe;
1353 int ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10001354
1355 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
1356 if (!disp)
1357 return -ENOMEM;
1358 dev_priv->engine.display.priv = disp;
1359
Ben Skeggs438d99e2011-07-05 16:48:06 +10001360 /* create crtc objects to represent the hw heads */
1361 for (i = 0; i < 2; i++) {
1362 ret = nvd0_crtc_create(dev, i);
1363 if (ret)
1364 goto out;
1365 }
1366
Ben Skeggs83fc0832011-07-05 13:08:40 +10001367 /* create encoder/connector objects based on VBIOS DCB table */
1368 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
1369 connector = nouveau_connector_create(dev, dcbe->connector);
1370 if (IS_ERR(connector))
1371 continue;
1372
1373 if (dcbe->location != DCB_LOC_ON_CHIP) {
1374 NV_WARN(dev, "skipping off-chip encoder %d/%d\n",
1375 dcbe->type, ffs(dcbe->or) - 1);
1376 continue;
1377 }
1378
1379 switch (dcbe->type) {
1380 case OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001381 case OUTPUT_LVDS:
Ben Skeggs83fc0832011-07-05 13:08:40 +10001382 nvd0_sor_create(connector, dcbe);
1383 break;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001384 case OUTPUT_ANALOG:
1385 nvd0_dac_create(connector, dcbe);
1386 break;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001387 default:
1388 NV_WARN(dev, "skipping unsupported encoder %d/%d\n",
1389 dcbe->type, ffs(dcbe->or) - 1);
1390 continue;
1391 }
1392 }
1393
1394 /* cull any connectors we created that don't have an encoder */
1395 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
1396 if (connector->encoder_ids[0])
1397 continue;
1398
1399 NV_WARN(dev, "%s has no encoders, removing\n",
1400 drm_get_connector_name(connector));
1401 connector->funcs->destroy(connector);
1402 }
1403
Ben Skeggs46005222011-07-05 11:01:13 +10001404 /* setup interrupt handling */
Ben Skeggsf20ce962011-07-08 13:17:01 +10001405 tasklet_init(&disp->tasklet, nvd0_display_bh, (unsigned long)dev);
Ben Skeggs46005222011-07-05 11:01:13 +10001406 nouveau_irq_register(dev, 26, nvd0_display_intr);
1407
Ben Skeggs51beb422011-07-05 10:33:08 +10001408 /* hash table and dma objects for the memory areas we care about */
Ben Skeggsefd272a2011-07-05 11:58:58 +10001409 ret = nouveau_gpuobj_new(dev, NULL, 0x4000, 0x10000,
1410 NVOBJ_FLAG_ZERO_ALLOC, &disp->mem);
Ben Skeggs26f6d882011-07-04 16:25:18 +10001411 if (ret)
1412 goto out;
1413
Ben Skeggsefd272a2011-07-05 11:58:58 +10001414 nv_wo32(disp->mem, 0x1000, 0x00000049);
1415 nv_wo32(disp->mem, 0x1004, (disp->mem->vinst + 0x2000) >> 8);
1416 nv_wo32(disp->mem, 0x1008, (disp->mem->vinst + 0x2fff) >> 8);
1417 nv_wo32(disp->mem, 0x100c, 0x00000000);
1418 nv_wo32(disp->mem, 0x1010, 0x00000000);
1419 nv_wo32(disp->mem, 0x1014, 0x00000000);
Ben Skeggs37b034a2011-07-08 14:43:19 +10001420 nv_wo32(disp->mem, 0x0000, NvEvoSync);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001421 nv_wo32(disp->mem, 0x0004, (0x1000 << 9) | 0x00000001);
1422
Ben Skeggsc0cc92a2011-07-06 11:40:45 +10001423 nv_wo32(disp->mem, 0x1020, 0x00000049);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001424 nv_wo32(disp->mem, 0x1024, 0x00000000);
1425 nv_wo32(disp->mem, 0x1028, (dev_priv->vram_size - 1) >> 8);
1426 nv_wo32(disp->mem, 0x102c, 0x00000000);
1427 nv_wo32(disp->mem, 0x1030, 0x00000000);
1428 nv_wo32(disp->mem, 0x1034, 0x00000000);
Ben Skeggs37b034a2011-07-08 14:43:19 +10001429 nv_wo32(disp->mem, 0x0008, NvEvoVRAM);
Ben Skeggsefd272a2011-07-05 11:58:58 +10001430 nv_wo32(disp->mem, 0x000c, (0x1020 << 9) | 0x00000001);
1431
Ben Skeggsc0cc92a2011-07-06 11:40:45 +10001432 nv_wo32(disp->mem, 0x1040, 0x00000009);
1433 nv_wo32(disp->mem, 0x1044, 0x00000000);
1434 nv_wo32(disp->mem, 0x1048, (dev_priv->vram_size - 1) >> 8);
1435 nv_wo32(disp->mem, 0x104c, 0x00000000);
1436 nv_wo32(disp->mem, 0x1050, 0x00000000);
1437 nv_wo32(disp->mem, 0x1054, 0x00000000);
1438 nv_wo32(disp->mem, 0x0010, NvEvoVRAM_LP);
1439 nv_wo32(disp->mem, 0x0014, (0x1040 << 9) | 0x00000001);
1440
1441 nv_wo32(disp->mem, 0x1060, 0x0fe00009);
1442 nv_wo32(disp->mem, 0x1064, 0x00000000);
1443 nv_wo32(disp->mem, 0x1068, (dev_priv->vram_size - 1) >> 8);
1444 nv_wo32(disp->mem, 0x106c, 0x00000000);
1445 nv_wo32(disp->mem, 0x1070, 0x00000000);
1446 nv_wo32(disp->mem, 0x1074, 0x00000000);
1447 nv_wo32(disp->mem, 0x0018, NvEvoFB32);
1448 nv_wo32(disp->mem, 0x001c, (0x1060 << 9) | 0x00000001);
1449
Ben Skeggsefd272a2011-07-05 11:58:58 +10001450 pinstmem->flush(dev);
1451
Ben Skeggs51beb422011-07-05 10:33:08 +10001452 /* push buffers for evo channels */
1453 disp->evo[0].ptr =
1454 pci_alloc_consistent(pdev, PAGE_SIZE, &disp->evo[0].handle);
1455 if (!disp->evo[0].ptr) {
1456 ret = -ENOMEM;
1457 goto out;
1458 }
1459
Ben Skeggs26f6d882011-07-04 16:25:18 +10001460 ret = nvd0_display_init(dev);
1461 if (ret)
1462 goto out;
1463
1464out:
1465 if (ret)
1466 nvd0_display_destroy(dev);
1467 return ret;
1468}