blob: 4c534b7b04daf032d29efdfc6365011eba2a74cf [file] [log] [blame]
Ben Skeggs56d237d2014-05-19 14:54:33 +10001/*
Ben Skeggs26f6d882011-07-04 16:25:18 +10002 * 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
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
28#include <drm/drm_crtc_helper.h>
Ben Skeggs48743222014-05-31 01:48:06 +100029#include <drm/drm_dp_helper.h>
Ben Skeggs26f6d882011-07-04 16:25:18 +100030
Ben Skeggs77145f12012-07-31 16:16:21 +100031#include "nouveau_drm.h"
32#include "nouveau_dma.h"
33#include "nouveau_gem.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100034#include "nouveau_connector.h"
35#include "nouveau_encoder.h"
36#include "nouveau_crtc.h"
Ben Skeggsf589be82012-07-22 11:55:54 +100037#include "nouveau_fence.h"
Ben Skeggs3a89cd02011-07-07 10:47:10 +100038#include "nv50_display.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100039
Ben Skeggsb5a794b2012-10-16 14:18:32 +100040#include <core/client.h>
Ben Skeggs77145f12012-07-31 16:16:21 +100041#include <core/gpuobj.h>
Ben Skeggsb5a794b2012-10-16 14:18:32 +100042#include <core/class.h>
Ben Skeggs77145f12012-07-31 16:16:21 +100043
44#include <subdev/timer.h>
45#include <subdev/bar.h>
46#include <subdev/fb.h>
Ben Skeggs5ed50202013-02-11 20:15:03 +100047#include <subdev/i2c.h>
Ben Skeggs77145f12012-07-31 16:16:21 +100048
Ben Skeggs8a464382011-11-12 23:52:07 +100049#define EVO_DMA_NR 9
50
Ben Skeggsbdb8c212011-11-12 01:30:24 +100051#define EVO_MASTER (0x00)
Ben Skeggsa63a97e2011-11-16 15:22:34 +100052#define EVO_FLIP(c) (0x01 + (c))
Ben Skeggs8a464382011-11-12 23:52:07 +100053#define EVO_OVLY(c) (0x05 + (c))
54#define EVO_OIMM(c) (0x09 + (c))
Ben Skeggsbdb8c212011-11-12 01:30:24 +100055#define EVO_CURS(c) (0x0d + (c))
56
Ben Skeggs816af2f2011-11-16 15:48:48 +100057/* offsets in shared sync bo of various structures */
58#define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +100059#define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
60#define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00)
61#define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10)
Ben Skeggs816af2f2011-11-16 15:48:48 +100062
Ben Skeggsb5a794b2012-10-16 14:18:32 +100063#define EVO_CORE_HANDLE (0xd1500000)
64#define EVO_CHAN_HANDLE(t,i) (0xd15c0000 | (((t) & 0x00ff) << 8) | (i))
65#define EVO_CHAN_OCLASS(t,c) ((nv_hclass(c) & 0xff00) | ((t) & 0x00ff))
66#define EVO_PUSH_HANDLE(t,i) (0xd15b0000 | (i) | \
67 (((NV50_DISP_##t##_CLASS) & 0x00ff) << 8))
68
69/******************************************************************************
70 * EVO channel
71 *****************************************************************************/
72
Ben Skeggse225f442012-11-21 14:40:21 +100073struct nv50_chan {
Ben Skeggsb5a794b2012-10-16 14:18:32 +100074 struct nouveau_object *user;
75 u32 handle;
76};
77
78static int
Ben Skeggse225f442012-11-21 14:40:21 +100079nv50_chan_create(struct nouveau_object *core, u32 bclass, u8 head,
80 void *data, u32 size, struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +100081{
82 struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
83 const u32 oclass = EVO_CHAN_OCLASS(bclass, core);
84 const u32 handle = EVO_CHAN_HANDLE(bclass, head);
85 int ret;
86
87 ret = nouveau_object_new(client, EVO_CORE_HANDLE, handle,
88 oclass, data, size, &chan->user);
89 if (ret)
90 return ret;
91
92 chan->handle = handle;
93 return 0;
94}
95
96static void
Ben Skeggse225f442012-11-21 14:40:21 +100097nv50_chan_destroy(struct nouveau_object *core, struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +100098{
99 struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
100 if (chan->handle)
101 nouveau_object_del(client, EVO_CORE_HANDLE, chan->handle);
102}
103
104/******************************************************************************
105 * PIO EVO channel
106 *****************************************************************************/
107
Ben Skeggse225f442012-11-21 14:40:21 +1000108struct nv50_pioc {
109 struct nv50_chan base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000110};
111
112static void
Ben Skeggse225f442012-11-21 14:40:21 +1000113nv50_pioc_destroy(struct nouveau_object *core, struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000114{
Ben Skeggse225f442012-11-21 14:40:21 +1000115 nv50_chan_destroy(core, &pioc->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000116}
117
118static int
Ben Skeggse225f442012-11-21 14:40:21 +1000119nv50_pioc_create(struct nouveau_object *core, u32 bclass, u8 head,
120 void *data, u32 size, struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000121{
Ben Skeggse225f442012-11-21 14:40:21 +1000122 return nv50_chan_create(core, bclass, head, data, size, &pioc->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000123}
124
125/******************************************************************************
126 * DMA EVO channel
127 *****************************************************************************/
128
Ben Skeggse225f442012-11-21 14:40:21 +1000129struct nv50_dmac {
130 struct nv50_chan base;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000131 dma_addr_t handle;
132 u32 *ptr;
Daniel Vetter59ad1462012-12-02 14:49:44 +0100133
134 /* Protects against concurrent pushbuf access to this channel, lock is
135 * grabbed by evo_wait (if the pushbuf reservation is successful) and
136 * dropped again by evo_kick. */
137 struct mutex lock;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000138};
139
140static void
Ben Skeggse225f442012-11-21 14:40:21 +1000141nv50_dmac_destroy(struct nouveau_object *core, struct nv50_dmac *dmac)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000142{
143 if (dmac->ptr) {
144 struct pci_dev *pdev = nv_device(core)->pdev;
145 pci_free_consistent(pdev, PAGE_SIZE, dmac->ptr, dmac->handle);
146 }
147
Ben Skeggse225f442012-11-21 14:40:21 +1000148 nv50_chan_destroy(core, &dmac->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000149}
150
151static int
Ben Skeggs47057302012-11-16 13:58:48 +1000152nv50_dmac_create_fbdma(struct nouveau_object *core, u32 parent)
153{
154 struct nouveau_fb *pfb = nouveau_fb(core);
155 struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
156 struct nouveau_object *object;
157 int ret = nouveau_object_new(client, parent, NvEvoVRAM_LP,
158 NV_DMA_IN_MEMORY_CLASS,
159 &(struct nv_dma_class) {
160 .flags = NV_DMA_TARGET_VRAM |
161 NV_DMA_ACCESS_RDWR,
162 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000163 .limit = pfb->ram->size - 1,
Ben Skeggs47057302012-11-16 13:58:48 +1000164 .conf0 = NV50_DMA_CONF0_ENABLE |
165 NV50_DMA_CONF0_PART_256,
166 }, sizeof(struct nv_dma_class), &object);
167 if (ret)
168 return ret;
169
170 ret = nouveau_object_new(client, parent, NvEvoFB16,
171 NV_DMA_IN_MEMORY_CLASS,
172 &(struct nv_dma_class) {
173 .flags = NV_DMA_TARGET_VRAM |
174 NV_DMA_ACCESS_RDWR,
175 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000176 .limit = pfb->ram->size - 1,
Ben Skeggs47057302012-11-16 13:58:48 +1000177 .conf0 = NV50_DMA_CONF0_ENABLE | 0x70 |
178 NV50_DMA_CONF0_PART_256,
179 }, sizeof(struct nv_dma_class), &object);
180 if (ret)
181 return ret;
182
183 ret = nouveau_object_new(client, parent, NvEvoFB32,
184 NV_DMA_IN_MEMORY_CLASS,
185 &(struct nv_dma_class) {
186 .flags = NV_DMA_TARGET_VRAM |
187 NV_DMA_ACCESS_RDWR,
188 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000189 .limit = pfb->ram->size - 1,
Ben Skeggs47057302012-11-16 13:58:48 +1000190 .conf0 = NV50_DMA_CONF0_ENABLE | 0x7a |
191 NV50_DMA_CONF0_PART_256,
192 }, sizeof(struct nv_dma_class), &object);
193 return ret;
194}
195
196static int
197nvc0_dmac_create_fbdma(struct nouveau_object *core, u32 parent)
198{
199 struct nouveau_fb *pfb = nouveau_fb(core);
200 struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
201 struct nouveau_object *object;
202 int ret = nouveau_object_new(client, parent, NvEvoVRAM_LP,
203 NV_DMA_IN_MEMORY_CLASS,
204 &(struct nv_dma_class) {
205 .flags = NV_DMA_TARGET_VRAM |
206 NV_DMA_ACCESS_RDWR,
207 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000208 .limit = pfb->ram->size - 1,
Ben Skeggs47057302012-11-16 13:58:48 +1000209 .conf0 = NVC0_DMA_CONF0_ENABLE,
210 }, sizeof(struct nv_dma_class), &object);
211 if (ret)
212 return ret;
213
214 ret = nouveau_object_new(client, parent, NvEvoFB16,
215 NV_DMA_IN_MEMORY_CLASS,
216 &(struct nv_dma_class) {
217 .flags = NV_DMA_TARGET_VRAM |
218 NV_DMA_ACCESS_RDWR,
219 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000220 .limit = pfb->ram->size - 1,
Ben Skeggs47057302012-11-16 13:58:48 +1000221 .conf0 = NVC0_DMA_CONF0_ENABLE | 0xfe,
222 }, sizeof(struct nv_dma_class), &object);
223 if (ret)
224 return ret;
225
226 ret = nouveau_object_new(client, parent, NvEvoFB32,
227 NV_DMA_IN_MEMORY_CLASS,
228 &(struct nv_dma_class) {
229 .flags = NV_DMA_TARGET_VRAM |
230 NV_DMA_ACCESS_RDWR,
231 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000232 .limit = pfb->ram->size - 1,
Ben Skeggs47057302012-11-16 13:58:48 +1000233 .conf0 = NVC0_DMA_CONF0_ENABLE | 0xfe,
234 }, sizeof(struct nv_dma_class), &object);
235 return ret;
236}
237
238static int
239nvd0_dmac_create_fbdma(struct nouveau_object *core, u32 parent)
240{
241 struct nouveau_fb *pfb = nouveau_fb(core);
242 struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
243 struct nouveau_object *object;
244 int ret = nouveau_object_new(client, parent, NvEvoVRAM_LP,
245 NV_DMA_IN_MEMORY_CLASS,
246 &(struct nv_dma_class) {
247 .flags = NV_DMA_TARGET_VRAM |
248 NV_DMA_ACCESS_RDWR,
249 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000250 .limit = pfb->ram->size - 1,
Ben Skeggs47057302012-11-16 13:58:48 +1000251 .conf0 = NVD0_DMA_CONF0_ENABLE |
252 NVD0_DMA_CONF0_PAGE_LP,
253 }, sizeof(struct nv_dma_class), &object);
254 if (ret)
255 return ret;
256
257 ret = nouveau_object_new(client, parent, NvEvoFB32,
258 NV_DMA_IN_MEMORY_CLASS,
259 &(struct nv_dma_class) {
260 .flags = NV_DMA_TARGET_VRAM |
261 NV_DMA_ACCESS_RDWR,
262 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000263 .limit = pfb->ram->size - 1,
Ben Skeggs47057302012-11-16 13:58:48 +1000264 .conf0 = NVD0_DMA_CONF0_ENABLE | 0xfe |
265 NVD0_DMA_CONF0_PAGE_LP,
266 }, sizeof(struct nv_dma_class), &object);
267 return ret;
268}
269
270static int
Ben Skeggse225f442012-11-21 14:40:21 +1000271nv50_dmac_create(struct nouveau_object *core, u32 bclass, u8 head,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000272 void *data, u32 size, u64 syncbuf,
Ben Skeggse225f442012-11-21 14:40:21 +1000273 struct nv50_dmac *dmac)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000274{
275 struct nouveau_fb *pfb = nouveau_fb(core);
276 struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
277 struct nouveau_object *object;
278 u32 pushbuf = *(u32 *)data;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000279 int ret;
280
Daniel Vetter59ad1462012-12-02 14:49:44 +0100281 mutex_init(&dmac->lock);
282
Ben Skeggs47057302012-11-16 13:58:48 +1000283 dmac->ptr = pci_alloc_consistent(nv_device(core)->pdev, PAGE_SIZE,
284 &dmac->handle);
285 if (!dmac->ptr)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000286 return -ENOMEM;
287
288 ret = nouveau_object_new(client, NVDRM_DEVICE, pushbuf,
289 NV_DMA_FROM_MEMORY_CLASS,
290 &(struct nv_dma_class) {
291 .flags = NV_DMA_TARGET_PCI_US |
292 NV_DMA_ACCESS_RD,
Ben Skeggs47057302012-11-16 13:58:48 +1000293 .start = dmac->handle + 0x0000,
294 .limit = dmac->handle + 0x0fff,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000295 }, sizeof(struct nv_dma_class), &object);
296 if (ret)
297 return ret;
298
Ben Skeggse225f442012-11-21 14:40:21 +1000299 ret = nv50_chan_create(core, bclass, head, data, size, &dmac->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000300 if (ret)
301 return ret;
302
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000303 ret = nouveau_object_new(client, dmac->base.handle, NvEvoSync,
304 NV_DMA_IN_MEMORY_CLASS,
305 &(struct nv_dma_class) {
306 .flags = NV_DMA_TARGET_VRAM |
307 NV_DMA_ACCESS_RDWR,
308 .start = syncbuf + 0x0000,
309 .limit = syncbuf + 0x0fff,
310 }, sizeof(struct nv_dma_class), &object);
311 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000312 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000313
314 ret = nouveau_object_new(client, dmac->base.handle, NvEvoVRAM,
315 NV_DMA_IN_MEMORY_CLASS,
316 &(struct nv_dma_class) {
317 .flags = NV_DMA_TARGET_VRAM |
318 NV_DMA_ACCESS_RDWR,
319 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000320 .limit = pfb->ram->size - 1,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000321 }, sizeof(struct nv_dma_class), &object);
322 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000323 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000324
Ben Skeggs47057302012-11-16 13:58:48 +1000325 if (nv_device(core)->card_type < NV_C0)
326 ret = nv50_dmac_create_fbdma(core, dmac->base.handle);
327 else
328 if (nv_device(core)->card_type < NV_D0)
329 ret = nvc0_dmac_create_fbdma(core, dmac->base.handle);
330 else
331 ret = nvd0_dmac_create_fbdma(core, dmac->base.handle);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000332 return ret;
333}
334
Ben Skeggse225f442012-11-21 14:40:21 +1000335struct nv50_mast {
336 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000337};
338
Ben Skeggse225f442012-11-21 14:40:21 +1000339struct nv50_curs {
340 struct nv50_pioc base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000341};
342
Ben Skeggse225f442012-11-21 14:40:21 +1000343struct nv50_sync {
344 struct nv50_dmac base;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000345 u32 addr;
346 u32 data;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000347};
348
Ben Skeggse225f442012-11-21 14:40:21 +1000349struct nv50_ovly {
350 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000351};
Ben Skeggsf20ce962011-07-08 13:17:01 +1000352
Ben Skeggse225f442012-11-21 14:40:21 +1000353struct nv50_oimm {
354 struct nv50_pioc base;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000355};
356
Ben Skeggse225f442012-11-21 14:40:21 +1000357struct nv50_head {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000358 struct nouveau_crtc base;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000359 struct nouveau_bo *image;
Ben Skeggse225f442012-11-21 14:40:21 +1000360 struct nv50_curs curs;
361 struct nv50_sync sync;
362 struct nv50_ovly ovly;
363 struct nv50_oimm oimm;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000364};
365
Ben Skeggse225f442012-11-21 14:40:21 +1000366#define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
367#define nv50_curs(c) (&nv50_head(c)->curs)
368#define nv50_sync(c) (&nv50_head(c)->sync)
369#define nv50_ovly(c) (&nv50_head(c)->ovly)
370#define nv50_oimm(c) (&nv50_head(c)->oimm)
371#define nv50_chan(c) (&(c)->base.base)
372#define nv50_vers(c) nv_mclass(nv50_chan(c)->user)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000373
Ben Skeggse225f442012-11-21 14:40:21 +1000374struct nv50_disp {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000375 struct nouveau_object *core;
Ben Skeggse225f442012-11-21 14:40:21 +1000376 struct nv50_mast mast;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000377
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000378 u32 modeset;
379
380 struct nouveau_bo *sync;
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000381};
382
Ben Skeggse225f442012-11-21 14:40:21 +1000383static struct nv50_disp *
384nv50_disp(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +1000385{
Ben Skeggs77145f12012-07-31 16:16:21 +1000386 return nouveau_display(dev)->priv;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000387}
388
Ben Skeggse225f442012-11-21 14:40:21 +1000389#define nv50_mast(d) (&nv50_disp(d)->mast)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000390
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000391static struct drm_crtc *
Ben Skeggse225f442012-11-21 14:40:21 +1000392nv50_display_crtc_get(struct drm_encoder *encoder)
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000393{
394 return nouveau_encoder(encoder)->crtc;
395}
396
397/******************************************************************************
398 * EVO channel helpers
399 *****************************************************************************/
Ben Skeggs51beb422011-07-05 10:33:08 +1000400static u32 *
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000401evo_wait(void *evoc, int nr)
Ben Skeggs51beb422011-07-05 10:33:08 +1000402{
Ben Skeggse225f442012-11-21 14:40:21 +1000403 struct nv50_dmac *dmac = evoc;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000404 u32 put = nv_ro32(dmac->base.user, 0x0000) / 4;
Ben Skeggs51beb422011-07-05 10:33:08 +1000405
Daniel Vetter59ad1462012-12-02 14:49:44 +0100406 mutex_lock(&dmac->lock);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000407 if (put + nr >= (PAGE_SIZE / 4) - 8) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000408 dmac->ptr[put] = 0x20000000;
Ben Skeggs51beb422011-07-05 10:33:08 +1000409
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000410 nv_wo32(dmac->base.user, 0x0000, 0x00000000);
411 if (!nv_wait(dmac->base.user, 0x0004, ~0, 0x00000000)) {
Daniel Vetter59ad1462012-12-02 14:49:44 +0100412 mutex_unlock(&dmac->lock);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000413 NV_ERROR(dmac->base.user, "channel stalled\n");
Ben Skeggs51beb422011-07-05 10:33:08 +1000414 return NULL;
415 }
416
417 put = 0;
418 }
419
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000420 return dmac->ptr + put;
Ben Skeggs51beb422011-07-05 10:33:08 +1000421}
422
423static void
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000424evo_kick(u32 *push, void *evoc)
Ben Skeggs51beb422011-07-05 10:33:08 +1000425{
Ben Skeggse225f442012-11-21 14:40:21 +1000426 struct nv50_dmac *dmac = evoc;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000427 nv_wo32(dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
Daniel Vetter59ad1462012-12-02 14:49:44 +0100428 mutex_unlock(&dmac->lock);
Ben Skeggs51beb422011-07-05 10:33:08 +1000429}
430
431#define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
432#define evo_data(p,d) *((p)++) = (d)
433
Ben Skeggs3376ee32011-11-12 14:28:12 +1000434static bool
435evo_sync_wait(void *data)
436{
Ben Skeggs5cc027f2013-02-18 17:50:51 -0500437 if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
438 return true;
439 usleep_range(1, 2);
440 return false;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000441}
442
443static int
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000444evo_sync(struct drm_device *dev)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000445{
Ben Skeggs77145f12012-07-31 16:16:21 +1000446 struct nouveau_device *device = nouveau_dev(dev);
Ben Skeggse225f442012-11-21 14:40:21 +1000447 struct nv50_disp *disp = nv50_disp(dev);
448 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000449 u32 *push = evo_wait(mast, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000450 if (push) {
Ben Skeggs816af2f2011-11-16 15:48:48 +1000451 nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000452 evo_mthd(push, 0x0084, 1);
Ben Skeggs816af2f2011-11-16 15:48:48 +1000453 evo_data(push, 0x80000000 | EVO_MAST_NTFY);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000454 evo_mthd(push, 0x0080, 2);
455 evo_data(push, 0x00000000);
456 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000457 evo_kick(push, mast);
Ben Skeggs77145f12012-07-31 16:16:21 +1000458 if (nv_wait_cb(device, evo_sync_wait, disp->sync))
Ben Skeggs3376ee32011-11-12 14:28:12 +1000459 return 0;
460 }
461
462 return -EBUSY;
463}
464
465/******************************************************************************
Ben Skeggsa63a97e2011-11-16 15:22:34 +1000466 * Page flipping channel
Ben Skeggs3376ee32011-11-12 14:28:12 +1000467 *****************************************************************************/
468struct nouveau_bo *
Ben Skeggse225f442012-11-21 14:40:21 +1000469nv50_display_crtc_sema(struct drm_device *dev, int crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000470{
Ben Skeggse225f442012-11-21 14:40:21 +1000471 return nv50_disp(dev)->sync;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000472}
473
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000474struct nv50_display_flip {
475 struct nv50_disp *disp;
476 struct nv50_sync *chan;
477};
478
479static bool
480nv50_display_flip_wait(void *data)
481{
482 struct nv50_display_flip *flip = data;
483 if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) ==
Calvin Owensb1ea3e62013-04-07 21:01:19 -0500484 flip->chan->data)
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000485 return true;
486 usleep_range(1, 2);
487 return false;
488}
489
Ben Skeggs3376ee32011-11-12 14:28:12 +1000490void
Ben Skeggse225f442012-11-21 14:40:21 +1000491nv50_display_flip_stop(struct drm_crtc *crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000492{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000493 struct nouveau_device *device = nouveau_dev(crtc->dev);
494 struct nv50_display_flip flip = {
495 .disp = nv50_disp(crtc->dev),
496 .chan = nv50_sync(crtc),
497 };
Ben Skeggs3376ee32011-11-12 14:28:12 +1000498 u32 *push;
499
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000500 push = evo_wait(flip.chan, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000501 if (push) {
502 evo_mthd(push, 0x0084, 1);
503 evo_data(push, 0x00000000);
504 evo_mthd(push, 0x0094, 1);
505 evo_data(push, 0x00000000);
506 evo_mthd(push, 0x00c0, 1);
507 evo_data(push, 0x00000000);
508 evo_mthd(push, 0x0080, 1);
509 evo_data(push, 0x00000000);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000510 evo_kick(push, flip.chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000511 }
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000512
513 nv_wait_cb(device, nv50_display_flip_wait, &flip);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000514}
515
516int
Ben Skeggse225f442012-11-21 14:40:21 +1000517nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Ben Skeggs3376ee32011-11-12 14:28:12 +1000518 struct nouveau_channel *chan, u32 swap_interval)
519{
520 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000521 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000522 struct nv50_head *head = nv50_head(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000523 struct nv50_sync *sync = nv50_sync(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000524 u32 *push;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000525 int ret;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000526
527 swap_interval <<= 4;
528 if (swap_interval == 0)
529 swap_interval |= 0x100;
Ben Skeggsf60b6e72013-03-19 15:20:00 +1000530 if (chan == NULL)
531 evo_sync(crtc->dev);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000532
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000533 push = evo_wait(sync, 128);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000534 if (unlikely(push == NULL))
535 return -EBUSY;
536
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000537 if (chan && nv_mclass(chan->object) < NV84_CHANNEL_IND_CLASS) {
538 ret = RING_SPACE(chan, 8);
539 if (ret)
540 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000541
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000542 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000543 OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000544 OUT_RING (chan, sync->addr ^ 0x10);
545 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
546 OUT_RING (chan, sync->data + 1);
547 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
548 OUT_RING (chan, sync->addr);
549 OUT_RING (chan, sync->data);
550 } else
551 if (chan && nv_mclass(chan->object) < NVC0_CHANNEL_IND_CLASS) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000552 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000553 ret = RING_SPACE(chan, 12);
554 if (ret)
555 return ret;
Ben Skeggsa34caf72013-02-14 09:28:37 +1000556
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000557 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
558 OUT_RING (chan, chan->vram);
559 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
560 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
561 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
562 OUT_RING (chan, sync->data + 1);
563 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
564 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
565 OUT_RING (chan, upper_32_bits(addr));
566 OUT_RING (chan, lower_32_bits(addr));
567 OUT_RING (chan, sync->data);
568 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
569 } else
570 if (chan) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000571 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000572 ret = RING_SPACE(chan, 10);
573 if (ret)
574 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000575
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000576 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
577 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
578 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
579 OUT_RING (chan, sync->data + 1);
580 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
581 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
582 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
583 OUT_RING (chan, upper_32_bits(addr));
584 OUT_RING (chan, lower_32_bits(addr));
585 OUT_RING (chan, sync->data);
586 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
587 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
588 }
Ben Skeggs35bcf5d2012-04-30 11:34:10 -0500589
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000590 if (chan) {
591 sync->addr ^= 0x10;
592 sync->data++;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000593 FIRE_RING (chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000594 }
595
596 /* queue the flip */
597 evo_mthd(push, 0x0100, 1);
598 evo_data(push, 0xfffe0000);
599 evo_mthd(push, 0x0084, 1);
600 evo_data(push, swap_interval);
601 if (!(swap_interval & 0x00000100)) {
602 evo_mthd(push, 0x00e0, 1);
603 evo_data(push, 0x40000000);
604 }
605 evo_mthd(push, 0x0088, 4);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000606 evo_data(push, sync->addr);
607 evo_data(push, sync->data++);
608 evo_data(push, sync->data);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000609 evo_data(push, NvEvoSync);
610 evo_mthd(push, 0x00a0, 2);
611 evo_data(push, 0x00000000);
612 evo_data(push, 0x00000000);
613 evo_mthd(push, 0x00c0, 1);
614 evo_data(push, nv_fb->r_dma);
615 evo_mthd(push, 0x0110, 2);
616 evo_data(push, 0x00000000);
617 evo_data(push, 0x00000000);
Ben Skeggse225f442012-11-21 14:40:21 +1000618 if (nv50_vers(sync) < NVD0_DISP_SYNC_CLASS) {
Ben Skeggsed5085a52012-11-16 13:16:51 +1000619 evo_mthd(push, 0x0800, 5);
620 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
621 evo_data(push, 0);
622 evo_data(push, (fb->height << 16) | fb->width);
623 evo_data(push, nv_fb->r_pitch);
624 evo_data(push, nv_fb->r_format);
625 } else {
626 evo_mthd(push, 0x0400, 5);
627 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
628 evo_data(push, 0);
629 evo_data(push, (fb->height << 16) | fb->width);
630 evo_data(push, nv_fb->r_pitch);
631 evo_data(push, nv_fb->r_format);
632 }
Ben Skeggs3376ee32011-11-12 14:28:12 +1000633 evo_mthd(push, 0x0080, 1);
634 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000635 evo_kick(push, sync);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000636
637 nouveau_bo_ref(nv_fb->nvbo, &head->image);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000638 return 0;
639}
640
Ben Skeggs26f6d882011-07-04 16:25:18 +1000641/******************************************************************************
Ben Skeggs438d99e2011-07-05 16:48:06 +1000642 * CRTC
643 *****************************************************************************/
644static int
Ben Skeggse225f442012-11-21 14:40:21 +1000645nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000646{
Ben Skeggse225f442012-11-21 14:40:21 +1000647 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde691852011-10-17 12:23:41 +1000648 struct nouveau_connector *nv_connector;
649 struct drm_connector *connector;
650 u32 *push, mode = 0x00;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000651
Ben Skeggs488ff202011-10-17 10:38:10 +1000652 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggsde691852011-10-17 12:23:41 +1000653 connector = &nv_connector->base;
654 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
Matt Roperf4510a22014-04-01 15:22:40 -0700655 if (nv_crtc->base.primary->fb->depth > connector->display_info.bpc * 3)
Ben Skeggsde691852011-10-17 12:23:41 +1000656 mode = DITHERING_MODE_DYNAMIC2X2;
657 } else {
658 mode = nv_connector->dithering_mode;
659 }
660
661 if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
662 if (connector->display_info.bpc >= 8)
663 mode |= DITHERING_DEPTH_8BPC;
664 } else {
665 mode |= nv_connector->dithering_depth;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000666 }
667
Ben Skeggsde8268c2012-11-16 10:24:31 +1000668 push = evo_wait(mast, 4);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000669 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000670 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000671 evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1);
672 evo_data(push, mode);
673 } else
Ben Skeggse225f442012-11-21 14:40:21 +1000674 if (nv50_vers(mast) < NVE0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000675 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1);
676 evo_data(push, mode);
677 } else {
678 evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1);
679 evo_data(push, mode);
680 }
681
Ben Skeggs438d99e2011-07-05 16:48:06 +1000682 if (update) {
683 evo_mthd(push, 0x0080, 1);
684 evo_data(push, 0x00000000);
685 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000686 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000687 }
688
689 return 0;
690}
691
692static int
Ben Skeggse225f442012-11-21 14:40:21 +1000693nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000694{
Ben Skeggse225f442012-11-21 14:40:21 +1000695 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs92854622011-11-11 23:49:06 +1000696 struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000697 struct drm_crtc *crtc = &nv_crtc->base;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000698 struct nouveau_connector *nv_connector;
Ben Skeggs92854622011-11-11 23:49:06 +1000699 int mode = DRM_MODE_SCALE_NONE;
700 u32 oX, oY, *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000701
Ben Skeggs92854622011-11-11 23:49:06 +1000702 /* start off at the resolution we programmed the crtc for, this
703 * effectively handles NONE/FULL scaling
704 */
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000705 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggs92854622011-11-11 23:49:06 +1000706 if (nv_connector && nv_connector->native_mode)
707 mode = nv_connector->scaling_mode;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000708
Ben Skeggs92854622011-11-11 23:49:06 +1000709 if (mode != DRM_MODE_SCALE_NONE)
710 omode = nv_connector->native_mode;
711 else
712 omode = umode;
713
714 oX = omode->hdisplay;
715 oY = omode->vdisplay;
716 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
717 oY *= 2;
718
719 /* add overscan compensation if necessary, will keep the aspect
720 * ratio the same as the backend mode unless overridden by the
721 * user setting both hborder and vborder properties.
722 */
723 if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
724 (nv_connector->underscan == UNDERSCAN_AUTO &&
725 nv_connector->edid &&
726 drm_detect_hdmi_monitor(nv_connector->edid)))) {
727 u32 bX = nv_connector->underscan_hborder;
728 u32 bY = nv_connector->underscan_vborder;
729 u32 aspect = (oY << 19) / oX;
730
731 if (bX) {
732 oX -= (bX * 2);
733 if (bY) oY -= (bY * 2);
734 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
735 } else {
736 oX -= (oX >> 4) + 32;
737 if (bY) oY -= (bY * 2);
738 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000739 }
740 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000741
Ben Skeggs92854622011-11-11 23:49:06 +1000742 /* handle CENTER/ASPECT scaling, taking into account the areas
743 * removed already for overscan compensation
744 */
745 switch (mode) {
746 case DRM_MODE_SCALE_CENTER:
747 oX = min((u32)umode->hdisplay, oX);
748 oY = min((u32)umode->vdisplay, oY);
749 /* fall-through */
750 case DRM_MODE_SCALE_ASPECT:
751 if (oY < oX) {
752 u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
753 oX = ((oY * aspect) + (aspect / 2)) >> 19;
754 } else {
755 u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
756 oY = ((oX * aspect) + (aspect / 2)) >> 19;
757 }
758 break;
759 default:
760 break;
761 }
762
Ben Skeggsde8268c2012-11-16 10:24:31 +1000763 push = evo_wait(mast, 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000764 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000765 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000766 /*XXX: SCALE_CTRL_ACTIVE??? */
767 evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2);
768 evo_data(push, (oY << 16) | oX);
769 evo_data(push, (oY << 16) | oX);
770 evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1);
771 evo_data(push, 0x00000000);
772 evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1);
773 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
774 } else {
775 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
776 evo_data(push, (oY << 16) | oX);
777 evo_data(push, (oY << 16) | oX);
778 evo_data(push, (oY << 16) | oX);
779 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
780 evo_data(push, 0x00000000);
781 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
782 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
783 }
784
785 evo_kick(push, mast);
786
Ben Skeggs3376ee32011-11-12 14:28:12 +1000787 if (update) {
Ben Skeggse225f442012-11-21 14:40:21 +1000788 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -0700789 nv50_display_flip_next(crtc, crtc->primary->fb,
790 NULL, 1);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000791 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000792 }
793
794 return 0;
795}
796
797static int
Ben Skeggse225f442012-11-21 14:40:21 +1000798nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggsf9887d02012-11-21 13:03:42 +1000799{
Ben Skeggse225f442012-11-21 14:40:21 +1000800 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsf9887d02012-11-21 13:03:42 +1000801 u32 *push, hue, vib;
802 int adj;
803
804 adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
805 vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
806 hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
807
808 push = evo_wait(mast, 16);
809 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000810 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsf9887d02012-11-21 13:03:42 +1000811 evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1);
812 evo_data(push, (hue << 20) | (vib << 8));
813 } else {
814 evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1);
815 evo_data(push, (hue << 20) | (vib << 8));
816 }
817
818 if (update) {
819 evo_mthd(push, 0x0080, 1);
820 evo_data(push, 0x00000000);
821 }
822 evo_kick(push, mast);
823 }
824
825 return 0;
826}
827
828static int
Ben Skeggse225f442012-11-21 14:40:21 +1000829nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000830 int x, int y, bool update)
831{
832 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
Ben Skeggse225f442012-11-21 14:40:21 +1000833 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000834 u32 *push;
835
Ben Skeggsde8268c2012-11-16 10:24:31 +1000836 push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000837 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000838 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000839 evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1);
840 evo_data(push, nvfb->nvbo->bo.offset >> 8);
841 evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3);
842 evo_data(push, (fb->height << 16) | fb->width);
843 evo_data(push, nvfb->r_pitch);
844 evo_data(push, nvfb->r_format);
845 evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1);
846 evo_data(push, (y << 16) | x);
Ben Skeggse225f442012-11-21 14:40:21 +1000847 if (nv50_vers(mast) > NV50_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000848 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
849 evo_data(push, nvfb->r_dma);
850 }
851 } else {
852 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
853 evo_data(push, nvfb->nvbo->bo.offset >> 8);
854 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
855 evo_data(push, (fb->height << 16) | fb->width);
856 evo_data(push, nvfb->r_pitch);
857 evo_data(push, nvfb->r_format);
858 evo_data(push, nvfb->r_dma);
859 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
860 evo_data(push, (y << 16) | x);
861 }
862
Ben Skeggsa46232e2011-07-07 15:23:48 +1000863 if (update) {
864 evo_mthd(push, 0x0080, 1);
865 evo_data(push, 0x00000000);
866 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000867 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000868 }
869
Ben Skeggsc0cc92a2011-07-06 11:40:45 +1000870 nv_crtc->fb.tile_flags = nvfb->r_dma;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000871 return 0;
872}
873
874static void
Ben Skeggse225f442012-11-21 14:40:21 +1000875nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000876{
Ben Skeggse225f442012-11-21 14:40:21 +1000877 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000878 u32 *push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000879 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000880 if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000881 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
882 evo_data(push, 0x85000000);
883 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
884 } else
Ben Skeggse225f442012-11-21 14:40:21 +1000885 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000886 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
887 evo_data(push, 0x85000000);
888 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
889 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
890 evo_data(push, NvEvoVRAM);
891 } else {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000892 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
893 evo_data(push, 0x85000000);
894 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
895 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
Ben Skeggs37b034a2011-07-08 14:43:19 +1000896 evo_data(push, NvEvoVRAM);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000897 }
898 evo_kick(push, mast);
899 }
900}
901
902static void
Ben Skeggse225f442012-11-21 14:40:21 +1000903nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000904{
Ben Skeggse225f442012-11-21 14:40:21 +1000905 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000906 u32 *push = evo_wait(mast, 16);
907 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000908 if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000909 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
910 evo_data(push, 0x05000000);
911 } else
Ben Skeggse225f442012-11-21 14:40:21 +1000912 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000913 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
914 evo_data(push, 0x05000000);
915 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
916 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000917 } else {
918 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
919 evo_data(push, 0x05000000);
920 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
921 evo_data(push, 0x00000000);
922 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000923 evo_kick(push, mast);
924 }
925}
Ben Skeggs438d99e2011-07-05 16:48:06 +1000926
Ben Skeggsde8268c2012-11-16 10:24:31 +1000927static void
Ben Skeggse225f442012-11-21 14:40:21 +1000928nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000929{
Ben Skeggse225f442012-11-21 14:40:21 +1000930 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000931
932 if (show)
Ben Skeggse225f442012-11-21 14:40:21 +1000933 nv50_crtc_cursor_show(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000934 else
Ben Skeggse225f442012-11-21 14:40:21 +1000935 nv50_crtc_cursor_hide(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000936
937 if (update) {
938 u32 *push = evo_wait(mast, 2);
939 if (push) {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000940 evo_mthd(push, 0x0080, 1);
941 evo_data(push, 0x00000000);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000942 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000943 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000944 }
945}
946
947static void
Ben Skeggse225f442012-11-21 14:40:21 +1000948nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000949{
950}
951
952static void
Ben Skeggse225f442012-11-21 14:40:21 +1000953nv50_crtc_prepare(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000954{
955 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000956 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000957 u32 *push;
958
Ben Skeggse225f442012-11-21 14:40:21 +1000959 nv50_display_flip_stop(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000960
Ben Skeggs56d237d2014-05-19 14:54:33 +1000961 push = evo_wait(mast, 6);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000962 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000963 if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000964 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
965 evo_data(push, 0x00000000);
966 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
967 evo_data(push, 0x40000000);
968 } else
Ben Skeggse225f442012-11-21 14:40:21 +1000969 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000970 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
971 evo_data(push, 0x00000000);
972 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
973 evo_data(push, 0x40000000);
974 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
975 evo_data(push, 0x00000000);
976 } else {
977 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
978 evo_data(push, 0x00000000);
979 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
980 evo_data(push, 0x03000000);
981 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
982 evo_data(push, 0x00000000);
983 }
984
985 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000986 }
987
Ben Skeggse225f442012-11-21 14:40:21 +1000988 nv50_crtc_cursor_show_hide(nv_crtc, false, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000989}
990
991static void
Ben Skeggse225f442012-11-21 14:40:21 +1000992nv50_crtc_commit(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000993{
994 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000995 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000996 u32 *push;
997
Ben Skeggsde8268c2012-11-16 10:24:31 +1000998 push = evo_wait(mast, 32);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000999 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +10001000 if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001001 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1002 evo_data(push, NvEvoVRAM_LP);
1003 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1004 evo_data(push, 0xc0000000);
1005 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1006 } else
Ben Skeggse225f442012-11-21 14:40:21 +10001007 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001008 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1009 evo_data(push, nv_crtc->fb.tile_flags);
1010 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1011 evo_data(push, 0xc0000000);
1012 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1013 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
1014 evo_data(push, NvEvoVRAM);
1015 } else {
1016 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
1017 evo_data(push, nv_crtc->fb.tile_flags);
1018 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
1019 evo_data(push, 0x83000000);
1020 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1021 evo_data(push, 0x00000000);
1022 evo_data(push, 0x00000000);
1023 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
1024 evo_data(push, NvEvoVRAM);
1025 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
1026 evo_data(push, 0xffffff00);
1027 }
1028
1029 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001030 }
1031
Ben Skeggse225f442012-11-21 14:40:21 +10001032 nv50_crtc_cursor_show_hide(nv_crtc, nv_crtc->cursor.visible, true);
Matt Roperf4510a22014-04-01 15:22:40 -07001033 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001034}
1035
1036static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001037nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001038 struct drm_display_mode *adjusted_mode)
1039{
Ben Skeggseb2e9682014-01-24 10:13:23 +10001040 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001041 return true;
1042}
1043
1044static int
Ben Skeggse225f442012-11-21 14:40:21 +10001045nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001046{
Matt Roperf4510a22014-04-01 15:22:40 -07001047 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001048 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001049 int ret;
1050
1051 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001052 if (ret == 0) {
1053 if (head->image)
1054 nouveau_bo_unpin(head->image);
1055 nouveau_bo_ref(nvfb->nvbo, &head->image);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001056 }
1057
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001058 return ret;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001059}
1060
1061static int
Ben Skeggse225f442012-11-21 14:40:21 +10001062nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001063 struct drm_display_mode *mode, int x, int y,
1064 struct drm_framebuffer *old_fb)
1065{
Ben Skeggse225f442012-11-21 14:40:21 +10001066 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001067 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1068 struct nouveau_connector *nv_connector;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001069 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
1070 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
1071 u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
1072 u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
1073 u32 vblan2e = 0, vblan2s = 1;
Ben Skeggs3488c572012-03-12 11:42:20 +10001074 u32 *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001075 int ret;
1076
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001077 hactive = mode->htotal;
1078 hsynce = mode->hsync_end - mode->hsync_start - 1;
1079 hbackp = mode->htotal - mode->hsync_end;
1080 hblanke = hsynce + hbackp;
1081 hfrontp = mode->hsync_start - mode->hdisplay;
1082 hblanks = mode->htotal - hfrontp - 1;
1083
1084 vactive = mode->vtotal * vscan / ilace;
1085 vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
1086 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
1087 vblanke = vsynce + vbackp;
1088 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
1089 vblanks = vactive - vfrontp - 1;
1090 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1091 vblan2e = vactive + vsynce + vbackp;
1092 vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
1093 vactive = (vactive * 2) + 1;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001094 }
1095
Ben Skeggse225f442012-11-21 14:40:21 +10001096 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001097 if (ret)
1098 return ret;
1099
Ben Skeggsde8268c2012-11-16 10:24:31 +10001100 push = evo_wait(mast, 64);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001101 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +10001102 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001103 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
1104 evo_data(push, 0x00800000 | mode->clock);
1105 evo_data(push, (ilace == 2) ? 2 : 0);
1106 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6);
1107 evo_data(push, 0x00000000);
1108 evo_data(push, (vactive << 16) | hactive);
1109 evo_data(push, ( vsynce << 16) | hsynce);
1110 evo_data(push, (vblanke << 16) | hblanke);
1111 evo_data(push, (vblanks << 16) | hblanks);
1112 evo_data(push, (vblan2e << 16) | vblan2s);
1113 evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1);
1114 evo_data(push, 0x00000000);
1115 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
1116 evo_data(push, 0x00000311);
1117 evo_data(push, 0x00000100);
1118 } else {
1119 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
1120 evo_data(push, 0x00000000);
1121 evo_data(push, (vactive << 16) | hactive);
1122 evo_data(push, ( vsynce << 16) | hsynce);
1123 evo_data(push, (vblanke << 16) | hblanke);
1124 evo_data(push, (vblanks << 16) | hblanks);
1125 evo_data(push, (vblan2e << 16) | vblan2s);
1126 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
1127 evo_data(push, 0x00000000); /* ??? */
1128 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
1129 evo_data(push, mode->clock * 1000);
1130 evo_data(push, 0x00200000); /* ??? */
1131 evo_data(push, mode->clock * 1000);
1132 evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
1133 evo_data(push, 0x00000311);
1134 evo_data(push, 0x00000100);
1135 }
1136
1137 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001138 }
1139
1140 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001141 nv50_crtc_set_dither(nv_crtc, false);
1142 nv50_crtc_set_scale(nv_crtc, false);
1143 nv50_crtc_set_color_vibrance(nv_crtc, false);
Matt Roperf4510a22014-04-01 15:22:40 -07001144 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001145 return 0;
1146}
1147
1148static int
Ben Skeggse225f442012-11-21 14:40:21 +10001149nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001150 struct drm_framebuffer *old_fb)
1151{
Ben Skeggs77145f12012-07-31 16:16:21 +10001152 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001153 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1154 int ret;
1155
Matt Roperf4510a22014-04-01 15:22:40 -07001156 if (!crtc->primary->fb) {
Ben Skeggs77145f12012-07-31 16:16:21 +10001157 NV_DEBUG(drm, "No FB bound\n");
Ben Skeggs84e2ad82011-08-26 09:40:39 +10001158 return 0;
1159 }
1160
Ben Skeggse225f442012-11-21 14:40:21 +10001161 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001162 if (ret)
1163 return ret;
1164
Ben Skeggse225f442012-11-21 14:40:21 +10001165 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -07001166 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
1167 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001168 return 0;
1169}
1170
1171static int
Ben Skeggse225f442012-11-21 14:40:21 +10001172nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001173 struct drm_framebuffer *fb, int x, int y,
1174 enum mode_set_atomic state)
1175{
1176 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001177 nv50_display_flip_stop(crtc);
1178 nv50_crtc_set_image(nv_crtc, fb, x, y, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001179 return 0;
1180}
1181
1182static void
Ben Skeggse225f442012-11-21 14:40:21 +10001183nv50_crtc_lut_load(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001184{
Ben Skeggse225f442012-11-21 14:40:21 +10001185 struct nv50_disp *disp = nv50_disp(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001186 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1187 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
1188 int i;
1189
1190 for (i = 0; i < 256; i++) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001191 u16 r = nv_crtc->lut.r[i] >> 2;
1192 u16 g = nv_crtc->lut.g[i] >> 2;
1193 u16 b = nv_crtc->lut.b[i] >> 2;
1194
1195 if (nv_mclass(disp->core) < NVD0_DISP_CLASS) {
1196 writew(r + 0x0000, lut + (i * 0x08) + 0);
1197 writew(g + 0x0000, lut + (i * 0x08) + 2);
1198 writew(b + 0x0000, lut + (i * 0x08) + 4);
1199 } else {
1200 writew(r + 0x6000, lut + (i * 0x20) + 0);
1201 writew(g + 0x6000, lut + (i * 0x20) + 2);
1202 writew(b + 0x6000, lut + (i * 0x20) + 4);
1203 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001204 }
1205}
1206
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001207static void
1208nv50_crtc_disable(struct drm_crtc *crtc)
1209{
1210 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsefa366f2014-06-05 12:56:35 +10001211 evo_sync(crtc->dev);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001212 if (head->image)
1213 nouveau_bo_unpin(head->image);
1214 nouveau_bo_ref(NULL, &head->image);
1215}
1216
Ben Skeggs438d99e2011-07-05 16:48:06 +10001217static int
Ben Skeggse225f442012-11-21 14:40:21 +10001218nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001219 uint32_t handle, uint32_t width, uint32_t height)
1220{
1221 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1222 struct drm_device *dev = crtc->dev;
1223 struct drm_gem_object *gem;
1224 struct nouveau_bo *nvbo;
1225 bool visible = (handle != 0);
1226 int i, ret = 0;
1227
1228 if (visible) {
1229 if (width != 64 || height != 64)
1230 return -EINVAL;
1231
1232 gem = drm_gem_object_lookup(dev, file_priv, handle);
1233 if (unlikely(!gem))
1234 return -ENOENT;
1235 nvbo = nouveau_gem_object(gem);
1236
1237 ret = nouveau_bo_map(nvbo);
1238 if (ret == 0) {
1239 for (i = 0; i < 64 * 64; i++) {
1240 u32 v = nouveau_bo_rd32(nvbo, i);
1241 nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v);
1242 }
1243 nouveau_bo_unmap(nvbo);
1244 }
1245
1246 drm_gem_object_unreference_unlocked(gem);
1247 }
1248
1249 if (visible != nv_crtc->cursor.visible) {
Ben Skeggse225f442012-11-21 14:40:21 +10001250 nv50_crtc_cursor_show_hide(nv_crtc, visible, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001251 nv_crtc->cursor.visible = visible;
1252 }
1253
1254 return ret;
1255}
1256
1257static int
Ben Skeggse225f442012-11-21 14:40:21 +10001258nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001259{
Ben Skeggse225f442012-11-21 14:40:21 +10001260 struct nv50_curs *curs = nv50_curs(crtc);
1261 struct nv50_chan *chan = nv50_chan(curs);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001262 nv_wo32(chan->user, 0x0084, (y << 16) | (x & 0xffff));
1263 nv_wo32(chan->user, 0x0080, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001264 return 0;
1265}
1266
1267static void
Ben Skeggse225f442012-11-21 14:40:21 +10001268nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001269 uint32_t start, uint32_t size)
1270{
1271 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Dan Carpenterbdefc8c2013-11-28 01:18:47 +03001272 u32 end = min_t(u32, start + size, 256);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001273 u32 i;
1274
1275 for (i = start; i < end; i++) {
1276 nv_crtc->lut.r[i] = r[i];
1277 nv_crtc->lut.g[i] = g[i];
1278 nv_crtc->lut.b[i] = b[i];
1279 }
1280
Ben Skeggse225f442012-11-21 14:40:21 +10001281 nv50_crtc_lut_load(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001282}
1283
1284static void
Ben Skeggse225f442012-11-21 14:40:21 +10001285nv50_crtc_destroy(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001286{
1287 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001288 struct nv50_disp *disp = nv50_disp(crtc->dev);
1289 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001290
Ben Skeggse225f442012-11-21 14:40:21 +10001291 nv50_dmac_destroy(disp->core, &head->ovly.base);
1292 nv50_pioc_destroy(disp->core, &head->oimm.base);
1293 nv50_dmac_destroy(disp->core, &head->sync.base);
1294 nv50_pioc_destroy(disp->core, &head->curs.base);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001295
1296 /*XXX: this shouldn't be necessary, but the core doesn't call
1297 * disconnect() during the cleanup paths
1298 */
1299 if (head->image)
1300 nouveau_bo_unpin(head->image);
1301 nouveau_bo_ref(NULL, &head->image);
1302
Ben Skeggs438d99e2011-07-05 16:48:06 +10001303 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001304 if (nv_crtc->cursor.nvbo)
1305 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001306 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001307
Ben Skeggs438d99e2011-07-05 16:48:06 +10001308 nouveau_bo_unmap(nv_crtc->lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001309 if (nv_crtc->lut.nvbo)
1310 nouveau_bo_unpin(nv_crtc->lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001311 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001312
Ben Skeggs438d99e2011-07-05 16:48:06 +10001313 drm_crtc_cleanup(crtc);
1314 kfree(crtc);
1315}
1316
Ben Skeggse225f442012-11-21 14:40:21 +10001317static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
1318 .dpms = nv50_crtc_dpms,
1319 .prepare = nv50_crtc_prepare,
1320 .commit = nv50_crtc_commit,
1321 .mode_fixup = nv50_crtc_mode_fixup,
1322 .mode_set = nv50_crtc_mode_set,
1323 .mode_set_base = nv50_crtc_mode_set_base,
1324 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
1325 .load_lut = nv50_crtc_lut_load,
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001326 .disable = nv50_crtc_disable,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001327};
1328
Ben Skeggse225f442012-11-21 14:40:21 +10001329static const struct drm_crtc_funcs nv50_crtc_func = {
1330 .cursor_set = nv50_crtc_cursor_set,
1331 .cursor_move = nv50_crtc_cursor_move,
1332 .gamma_set = nv50_crtc_gamma_set,
Dave Airlie5addcf02012-09-10 14:20:51 +10001333 .set_config = nouveau_crtc_set_config,
Ben Skeggse225f442012-11-21 14:40:21 +10001334 .destroy = nv50_crtc_destroy,
Ben Skeggs3376ee32011-11-12 14:28:12 +10001335 .page_flip = nouveau_crtc_page_flip,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001336};
1337
Ben Skeggsc20ab3e2011-08-25 14:09:43 +10001338static void
Ben Skeggse225f442012-11-21 14:40:21 +10001339nv50_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
Ben Skeggsc20ab3e2011-08-25 14:09:43 +10001340{
1341}
1342
1343static void
Ben Skeggse225f442012-11-21 14:40:21 +10001344nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
Ben Skeggsc20ab3e2011-08-25 14:09:43 +10001345{
1346}
1347
Ben Skeggs438d99e2011-07-05 16:48:06 +10001348static int
Ben Skeggse225f442012-11-21 14:40:21 +10001349nv50_crtc_create(struct drm_device *dev, struct nouveau_object *core, int index)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001350{
Ben Skeggse225f442012-11-21 14:40:21 +10001351 struct nv50_disp *disp = nv50_disp(dev);
1352 struct nv50_head *head;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001353 struct drm_crtc *crtc;
1354 int ret, i;
1355
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001356 head = kzalloc(sizeof(*head), GFP_KERNEL);
1357 if (!head)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001358 return -ENOMEM;
1359
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001360 head->base.index = index;
Ben Skeggse225f442012-11-21 14:40:21 +10001361 head->base.set_dither = nv50_crtc_set_dither;
1362 head->base.set_scale = nv50_crtc_set_scale;
1363 head->base.set_color_vibrance = nv50_crtc_set_color_vibrance;
Ben Skeggsf9887d02012-11-21 13:03:42 +10001364 head->base.color_vibrance = 50;
1365 head->base.vibrant_hue = 0;
Ben Skeggse225f442012-11-21 14:40:21 +10001366 head->base.cursor.set_offset = nv50_cursor_set_offset;
1367 head->base.cursor.set_pos = nv50_cursor_set_pos;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001368 for (i = 0; i < 256; i++) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001369 head->base.lut.r[i] = i << 8;
1370 head->base.lut.g[i] = i << 8;
1371 head->base.lut.b[i] = i << 8;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001372 }
1373
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001374 crtc = &head->base.base;
Ben Skeggse225f442012-11-21 14:40:21 +10001375 drm_crtc_init(dev, crtc, &nv50_crtc_func);
1376 drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001377 drm_mode_crtc_set_gamma_size(crtc, 256);
1378
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +10001379 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001380 0, 0x0000, NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001381 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001382 ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001383 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001384 ret = nouveau_bo_map(head->base.lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001385 if (ret)
1386 nouveau_bo_unpin(head->base.lut.nvbo);
1387 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001388 if (ret)
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001389 nouveau_bo_ref(NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001390 }
1391
1392 if (ret)
1393 goto out;
1394
Ben Skeggse225f442012-11-21 14:40:21 +10001395 nv50_crtc_lut_load(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001396
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001397 /* allocate cursor resources */
Ben Skeggse225f442012-11-21 14:40:21 +10001398 ret = nv50_pioc_create(disp->core, NV50_DISP_CURS_CLASS, index,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001399 &(struct nv50_display_curs_class) {
1400 .head = index,
1401 }, sizeof(struct nv50_display_curs_class),
1402 &head->curs.base);
1403 if (ret)
1404 goto out;
1405
1406 ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM,
1407 0, 0x0000, NULL, &head->base.cursor.nvbo);
1408 if (!ret) {
1409 ret = nouveau_bo_pin(head->base.cursor.nvbo, TTM_PL_FLAG_VRAM);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001410 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001411 ret = nouveau_bo_map(head->base.cursor.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001412 if (ret)
1413 nouveau_bo_unpin(head->base.lut.nvbo);
1414 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001415 if (ret)
1416 nouveau_bo_ref(NULL, &head->base.cursor.nvbo);
1417 }
1418
1419 if (ret)
1420 goto out;
1421
1422 /* allocate page flip / sync resources */
Ben Skeggse225f442012-11-21 14:40:21 +10001423 ret = nv50_dmac_create(disp->core, NV50_DISP_SYNC_CLASS, index,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001424 &(struct nv50_display_sync_class) {
1425 .pushbuf = EVO_PUSH_HANDLE(SYNC, index),
1426 .head = index,
1427 }, sizeof(struct nv50_display_sync_class),
1428 disp->sync->bo.offset, &head->sync.base);
1429 if (ret)
1430 goto out;
1431
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001432 head->sync.addr = EVO_FLIP_SEM0(index);
1433 head->sync.data = 0x00000000;
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001434
1435 /* allocate overlay resources */
Ben Skeggse225f442012-11-21 14:40:21 +10001436 ret = nv50_pioc_create(disp->core, NV50_DISP_OIMM_CLASS, index,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001437 &(struct nv50_display_oimm_class) {
1438 .head = index,
1439 }, sizeof(struct nv50_display_oimm_class),
1440 &head->oimm.base);
1441 if (ret)
1442 goto out;
1443
Ben Skeggse225f442012-11-21 14:40:21 +10001444 ret = nv50_dmac_create(disp->core, NV50_DISP_OVLY_CLASS, index,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001445 &(struct nv50_display_ovly_class) {
1446 .pushbuf = EVO_PUSH_HANDLE(OVLY, index),
1447 .head = index,
1448 }, sizeof(struct nv50_display_ovly_class),
1449 disp->sync->bo.offset, &head->ovly.base);
1450 if (ret)
1451 goto out;
1452
Ben Skeggs438d99e2011-07-05 16:48:06 +10001453out:
1454 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10001455 nv50_crtc_destroy(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001456 return ret;
1457}
1458
1459/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001460 * DAC
1461 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001462static void
Ben Skeggse225f442012-11-21 14:40:21 +10001463nv50_dac_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001464{
1465 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001466 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001467 int or = nv_encoder->or;
1468 u32 dpms_ctrl;
1469
Ben Skeggs35b21d32012-11-08 12:08:55 +10001470 dpms_ctrl = 0x00000000;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001471 if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF)
1472 dpms_ctrl |= 0x00000001;
1473 if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF)
1474 dpms_ctrl |= 0x00000004;
1475
Ben Skeggs35b21d32012-11-08 12:08:55 +10001476 nv_call(disp->core, NV50_DISP_DAC_PWR + or, dpms_ctrl);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001477}
1478
1479static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001480nv50_dac_mode_fixup(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +02001481 const struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001482 struct drm_display_mode *adjusted_mode)
1483{
1484 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1485 struct nouveau_connector *nv_connector;
1486
1487 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1488 if (nv_connector && nv_connector->native_mode) {
1489 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
1490 int id = adjusted_mode->base.id;
1491 *adjusted_mode = *nv_connector->native_mode;
1492 adjusted_mode->base.id = id;
1493 }
1494 }
1495
1496 return true;
1497}
1498
1499static void
Ben Skeggse225f442012-11-21 14:40:21 +10001500nv50_dac_commit(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001501{
1502}
1503
1504static void
Ben Skeggse225f442012-11-21 14:40:21 +10001505nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001506 struct drm_display_mode *adjusted_mode)
1507{
Ben Skeggse225f442012-11-21 14:40:21 +10001508 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001509 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1510 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001511 u32 *push;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001512
Ben Skeggse225f442012-11-21 14:40:21 +10001513 nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001514
Ben Skeggs97b19b52012-11-16 11:21:37 +10001515 push = evo_wait(mast, 8);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001516 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +10001517 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001518 u32 syncs = 0x00000000;
1519
1520 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1521 syncs |= 0x00000001;
1522 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1523 syncs |= 0x00000002;
1524
1525 evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
1526 evo_data(push, 1 << nv_crtc->index);
1527 evo_data(push, syncs);
1528 } else {
1529 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1530 u32 syncs = 0x00000001;
1531
1532 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1533 syncs |= 0x00000008;
1534 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1535 syncs |= 0x00000010;
1536
1537 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1538 magic |= 0x00000001;
1539
1540 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1541 evo_data(push, syncs);
1542 evo_data(push, magic);
1543 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
1544 evo_data(push, 1 << nv_crtc->index);
1545 }
1546
1547 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001548 }
1549
1550 nv_encoder->crtc = encoder->crtc;
1551}
1552
1553static void
Ben Skeggse225f442012-11-21 14:40:21 +10001554nv50_dac_disconnect(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001555{
1556 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001557 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001558 const int or = nv_encoder->or;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001559 u32 *push;
1560
1561 if (nv_encoder->crtc) {
Ben Skeggse225f442012-11-21 14:40:21 +10001562 nv50_crtc_prepare(nv_encoder->crtc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001563
Ben Skeggs97b19b52012-11-16 11:21:37 +10001564 push = evo_wait(mast, 4);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001565 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +10001566 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001567 evo_mthd(push, 0x0400 + (or * 0x080), 1);
1568 evo_data(push, 0x00000000);
1569 } else {
1570 evo_mthd(push, 0x0180 + (or * 0x020), 1);
1571 evo_data(push, 0x00000000);
1572 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001573 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001574 }
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001575 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001576
1577 nv_encoder->crtc = NULL;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001578}
1579
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001580static enum drm_connector_status
Ben Skeggse225f442012-11-21 14:40:21 +10001581nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001582{
Ben Skeggse225f442012-11-21 14:40:21 +10001583 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs35b21d32012-11-08 12:08:55 +10001584 int ret, or = nouveau_encoder(encoder)->or;
Ben Skeggsd40ee482013-06-03 16:40:14 +10001585 u32 load = nouveau_drm(encoder->dev)->vbios.dactestval;
1586 if (load == 0)
1587 load = 340;
Ben Skeggsb6819932011-07-08 11:14:50 +10001588
Ben Skeggs35b21d32012-11-08 12:08:55 +10001589 ret = nv_exec(disp->core, NV50_DISP_DAC_LOAD + or, &load, sizeof(load));
Ben Skeggs4b31ebc2013-09-04 11:01:42 +10001590 if (ret || !load)
Ben Skeggs35b21d32012-11-08 12:08:55 +10001591 return connector_status_disconnected;
Ben Skeggsb6819932011-07-08 11:14:50 +10001592
Ben Skeggs35b21d32012-11-08 12:08:55 +10001593 return connector_status_connected;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001594}
1595
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001596static void
Ben Skeggse225f442012-11-21 14:40:21 +10001597nv50_dac_destroy(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001598{
1599 drm_encoder_cleanup(encoder);
1600 kfree(encoder);
1601}
1602
Ben Skeggse225f442012-11-21 14:40:21 +10001603static const struct drm_encoder_helper_funcs nv50_dac_hfunc = {
1604 .dpms = nv50_dac_dpms,
1605 .mode_fixup = nv50_dac_mode_fixup,
1606 .prepare = nv50_dac_disconnect,
1607 .commit = nv50_dac_commit,
1608 .mode_set = nv50_dac_mode_set,
1609 .disable = nv50_dac_disconnect,
1610 .get_crtc = nv50_display_crtc_get,
1611 .detect = nv50_dac_detect
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001612};
1613
Ben Skeggse225f442012-11-21 14:40:21 +10001614static const struct drm_encoder_funcs nv50_dac_func = {
1615 .destroy = nv50_dac_destroy,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001616};
1617
1618static int
Ben Skeggse225f442012-11-21 14:40:21 +10001619nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001620{
Ben Skeggs5ed50202013-02-11 20:15:03 +10001621 struct nouveau_drm *drm = nouveau_drm(connector->dev);
1622 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001623 struct nouveau_encoder *nv_encoder;
1624 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001625 int type = DRM_MODE_ENCODER_DAC;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001626
1627 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1628 if (!nv_encoder)
1629 return -ENOMEM;
1630 nv_encoder->dcb = dcbe;
1631 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001632 nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001633
1634 encoder = to_drm_encoder(nv_encoder);
1635 encoder->possible_crtcs = dcbe->heads;
1636 encoder->possible_clones = 0;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001637 drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type);
Ben Skeggse225f442012-11-21 14:40:21 +10001638 drm_encoder_helper_add(encoder, &nv50_dac_hfunc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001639
1640 drm_mode_connector_attach_encoder(connector, encoder);
1641 return 0;
1642}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001643
1644/******************************************************************************
Ben Skeggs78951d22011-11-11 18:13:13 +10001645 * Audio
1646 *****************************************************************************/
1647static void
Ben Skeggse225f442012-11-21 14:40:21 +10001648nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001649{
1650 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1651 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10001652 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001653
1654 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1655 if (!drm_detect_monitor_audio(nv_connector->edid))
1656 return;
1657
Ben Skeggs78951d22011-11-11 18:13:13 +10001658 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
Ben Skeggs78951d22011-11-11 18:13:13 +10001659
Ben Skeggs0a9e2b952012-11-08 14:03:56 +10001660 nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or,
1661 nv_connector->base.eld,
1662 nv_connector->base.eld[2] * 4);
Ben Skeggs78951d22011-11-11 18:13:13 +10001663}
1664
1665static void
Ben Skeggse225f442012-11-21 14:40:21 +10001666nv50_audio_disconnect(struct drm_encoder *encoder)
Ben Skeggs78951d22011-11-11 18:13:13 +10001667{
1668 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001669 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001670
Ben Skeggs0a9e2b952012-11-08 14:03:56 +10001671 nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or, NULL, 0);
Ben Skeggs78951d22011-11-11 18:13:13 +10001672}
1673
1674/******************************************************************************
1675 * HDMI
1676 *****************************************************************************/
1677static void
Ben Skeggse225f442012-11-21 14:40:21 +10001678nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001679{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001680 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1681 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1682 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10001683 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs1c30cd02012-11-08 14:22:28 +10001684 const u32 moff = (nv_crtc->index << 3) | nv_encoder->or;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001685 u32 rekey = 56; /* binary driver, and tegra constant */
1686 u32 max_ac_packet;
1687
1688 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1689 if (!drm_detect_hdmi_monitor(nv_connector->edid))
1690 return;
1691
1692 max_ac_packet = mode->htotal - mode->hdisplay;
1693 max_ac_packet -= rekey;
1694 max_ac_packet -= 18; /* constant from tegra */
1695 max_ac_packet /= 32;
1696
Ben Skeggs1c30cd02012-11-08 14:22:28 +10001697 nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff,
1698 NV84_DISP_SOR_HDMI_PWR_STATE_ON |
1699 (max_ac_packet << 16) | rekey);
Ben Skeggs091e40c2011-11-11 20:46:00 +10001700
Ben Skeggse225f442012-11-21 14:40:21 +10001701 nv50_audio_mode_set(encoder, mode);
Ben Skeggs78951d22011-11-11 18:13:13 +10001702}
1703
1704static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001705nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001706{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001707 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001708 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs1c30cd02012-11-08 14:22:28 +10001709 const u32 moff = (nv_crtc->index << 3) | nv_encoder->or;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001710
Ben Skeggse225f442012-11-21 14:40:21 +10001711 nv50_audio_disconnect(encoder);
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001712
Ben Skeggs1c30cd02012-11-08 14:22:28 +10001713 nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff, 0x00000000);
Ben Skeggs78951d22011-11-11 18:13:13 +10001714}
1715
1716/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001717 * SOR
1718 *****************************************************************************/
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001719static void
Ben Skeggse225f442012-11-21 14:40:21 +10001720nv50_sor_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001721{
1722 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1723 struct drm_device *dev = encoder->dev;
Ben Skeggse225f442012-11-21 14:40:21 +10001724 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001725 struct drm_encoder *partner;
Ben Skeggs48743222014-05-31 01:48:06 +10001726 u32 mthd;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001727
1728 nv_encoder->last_dpms = mode;
1729
1730 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
1731 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
1732
1733 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
1734 continue;
1735
1736 if (nv_partner != nv_encoder &&
Ben Skeggs26cfa812011-11-17 09:10:02 +10001737 nv_partner->dcb->or == nv_encoder->dcb->or) {
Ben Skeggs83fc0832011-07-05 13:08:40 +10001738 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
1739 return;
1740 break;
1741 }
1742 }
1743
Ben Skeggs276e5262014-06-30 11:10:02 +10001744 mthd = (ffs(nv_encoder->dcb->heads) - 1) << 3;
1745 mthd |= (ffs(nv_encoder->dcb->sorconf.link) - 1) << 2;
Ben Skeggs48743222014-05-31 01:48:06 +10001746 mthd |= nv_encoder->or;
1747
1748 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
1749 nv_call(disp->core, NV50_DISP_SOR_PWR | mthd, 1);
1750 mthd |= NV94_DISP_SOR_DP_PWR;
1751 } else {
1752 mthd |= NV50_DISP_SOR_PWR;
1753 }
1754
1755 nv_call(disp->core, mthd, (mode == DRM_MODE_DPMS_ON));
Ben Skeggs83fc0832011-07-05 13:08:40 +10001756}
1757
1758static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001759nv50_sor_mode_fixup(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +02001760 const struct drm_display_mode *mode,
Ben Skeggs83fc0832011-07-05 13:08:40 +10001761 struct drm_display_mode *adjusted_mode)
1762{
1763 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1764 struct nouveau_connector *nv_connector;
1765
1766 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1767 if (nv_connector && nv_connector->native_mode) {
1768 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
1769 int id = adjusted_mode->base.id;
1770 *adjusted_mode = *nv_connector->native_mode;
1771 adjusted_mode->base.id = id;
1772 }
1773 }
1774
1775 return true;
1776}
1777
1778static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001779nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
1780{
1781 struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
1782 u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
1783 if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
1784 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
1785 evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
1786 evo_data(push, (nv_encoder->ctrl = temp));
1787 } else {
1788 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
1789 evo_data(push, (nv_encoder->ctrl = temp));
1790 }
1791 evo_kick(push, mast);
1792 }
1793}
1794
1795static void
Ben Skeggse225f442012-11-21 14:40:21 +10001796nv50_sor_disconnect(struct drm_encoder *encoder)
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001797{
1798 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001799 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001800
1801 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1802 nv_encoder->crtc = NULL;
Ben Skeggse84a35a2014-06-05 10:59:55 +10001803
1804 if (nv_crtc) {
1805 nv50_crtc_prepare(&nv_crtc->base);
1806 nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
1807 nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc);
1808 }
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001809}
1810
1811static void
Ben Skeggse225f442012-11-21 14:40:21 +10001812nv50_sor_commit(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001813{
1814}
1815
1816static void
Ben Skeggse225f442012-11-21 14:40:21 +10001817nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001818 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001819{
Ben Skeggse225f442012-11-21 14:40:21 +10001820 struct nv50_disp *disp = nv50_disp(encoder->dev);
1821 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001822 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +10001823 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001824 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1825 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001826 struct nouveau_connector *nv_connector;
Ben Skeggs77145f12012-07-31 16:16:21 +10001827 struct nvbios *bios = &drm->vbios;
Ben Skeggse84a35a2014-06-05 10:59:55 +10001828 u32 lvds = 0, mask, ctrl;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001829 u8 owner = 1 << nv_crtc->index;
1830 u8 proto = 0xf;
1831 u8 depth = 0x0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001832
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001833 nv_connector = nouveau_encoder_connector_get(nv_encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001834 nv_encoder->crtc = encoder->crtc;
1835
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001836 switch (nv_encoder->dcb->type) {
Ben Skeggscb75d972012-07-11 10:44:20 +10001837 case DCB_OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001838 if (nv_encoder->dcb->sorconf.link & 1) {
1839 if (mode->clock < 165000)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001840 proto = 0x1;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001841 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001842 proto = 0x5;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001843 } else {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001844 proto = 0x2;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001845 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001846
Ben Skeggse84a35a2014-06-05 10:59:55 +10001847 nv50_hdmi_mode_set(&nv_encoder->base.base, mode);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001848 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001849 case DCB_OUTPUT_LVDS:
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001850 proto = 0x0;
1851
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001852 if (bios->fp_no_ddc) {
1853 if (bios->fp.dual_link)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001854 lvds |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001855 if (bios->fp.if_is_24bit)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001856 lvds |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001857 } else {
Ben Skeggsbefb51e2011-11-18 10:23:59 +10001858 if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001859 if (((u8 *)nv_connector->edid)[121] == 2)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001860 lvds |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001861 } else
1862 if (mode->clock >= bios->fp.duallink_transition_clk) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001863 lvds |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001864 }
1865
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001866 if (lvds & 0x0100) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001867 if (bios->fp.strapless_is_24bit & 2)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001868 lvds |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001869 } else {
1870 if (bios->fp.strapless_is_24bit & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001871 lvds |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001872 }
1873
1874 if (nv_connector->base.display_info.bpc == 8)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001875 lvds |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001876 }
Ben Skeggs4a230fa2012-11-09 11:25:37 +10001877
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001878 nv_call(disp->core, NV50_DISP_SOR_LVDS_SCRIPT + nv_encoder->or, lvds);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001879 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001880 case DCB_OUTPUT_DP:
Ben Skeggs3488c572012-03-12 11:42:20 +10001881 if (nv_connector->base.display_info.bpc == 6) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001882 nv_encoder->dp.datarate = mode->clock * 18 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001883 depth = 0x2;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10001884 } else
1885 if (nv_connector->base.display_info.bpc == 8) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001886 nv_encoder->dp.datarate = mode->clock * 24 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001887 depth = 0x5;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10001888 } else {
1889 nv_encoder->dp.datarate = mode->clock * 30 / 8;
1890 depth = 0x6;
Ben Skeggs3488c572012-03-12 11:42:20 +10001891 }
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001892
1893 if (nv_encoder->dcb->sorconf.link & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001894 proto = 0x8;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001895 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001896 proto = 0x9;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001897 break;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001898 default:
1899 BUG_ON(1);
1900 break;
1901 }
Ben Skeggsff8ff502011-07-08 11:53:37 +10001902
Ben Skeggse84a35a2014-06-05 10:59:55 +10001903 nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001904
Ben Skeggse84a35a2014-06-05 10:59:55 +10001905 if (nv50_vers(mast) >= NVD0_DISP_CLASS) {
1906 u32 *push = evo_wait(mast, 3);
1907 if (push) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001908 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1909 u32 syncs = 0x00000001;
1910
1911 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1912 syncs |= 0x00000008;
1913 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1914 syncs |= 0x00000010;
1915
1916 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1917 magic |= 0x00000001;
1918
1919 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1920 evo_data(push, syncs | (depth << 6));
1921 evo_data(push, magic);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001922 evo_kick(push, mast);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001923 }
1924
Ben Skeggse84a35a2014-06-05 10:59:55 +10001925 ctrl = proto << 8;
1926 mask = 0x00000f00;
1927 } else {
1928 ctrl = (depth << 16) | (proto << 8);
1929 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1930 ctrl |= 0x00001000;
1931 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1932 ctrl |= 0x00002000;
1933 mask = 0x000f3f00;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001934 }
1935
Ben Skeggse84a35a2014-06-05 10:59:55 +10001936 nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001937}
1938
1939static void
Ben Skeggse225f442012-11-21 14:40:21 +10001940nv50_sor_destroy(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001941{
1942 drm_encoder_cleanup(encoder);
1943 kfree(encoder);
1944}
1945
Ben Skeggse225f442012-11-21 14:40:21 +10001946static const struct drm_encoder_helper_funcs nv50_sor_hfunc = {
1947 .dpms = nv50_sor_dpms,
1948 .mode_fixup = nv50_sor_mode_fixup,
Ben Skeggs5a885f02013-02-20 14:34:18 +10001949 .prepare = nv50_sor_disconnect,
Ben Skeggse225f442012-11-21 14:40:21 +10001950 .commit = nv50_sor_commit,
1951 .mode_set = nv50_sor_mode_set,
1952 .disable = nv50_sor_disconnect,
1953 .get_crtc = nv50_display_crtc_get,
Ben Skeggs83fc0832011-07-05 13:08:40 +10001954};
1955
Ben Skeggse225f442012-11-21 14:40:21 +10001956static const struct drm_encoder_funcs nv50_sor_func = {
1957 .destroy = nv50_sor_destroy,
Ben Skeggs83fc0832011-07-05 13:08:40 +10001958};
1959
1960static int
Ben Skeggse225f442012-11-21 14:40:21 +10001961nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001962{
Ben Skeggs5ed50202013-02-11 20:15:03 +10001963 struct nouveau_drm *drm = nouveau_drm(connector->dev);
1964 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001965 struct nouveau_encoder *nv_encoder;
1966 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001967 int type;
1968
1969 switch (dcbe->type) {
1970 case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
1971 case DCB_OUTPUT_TMDS:
1972 case DCB_OUTPUT_DP:
1973 default:
1974 type = DRM_MODE_ENCODER_TMDS;
1975 break;
1976 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001977
1978 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1979 if (!nv_encoder)
1980 return -ENOMEM;
1981 nv_encoder->dcb = dcbe;
1982 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001983 nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001984 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1985
1986 encoder = to_drm_encoder(nv_encoder);
1987 encoder->possible_crtcs = dcbe->heads;
1988 encoder->possible_clones = 0;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001989 drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type);
Ben Skeggse225f442012-11-21 14:40:21 +10001990 drm_encoder_helper_add(encoder, &nv50_sor_hfunc);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001991
1992 drm_mode_connector_attach_encoder(connector, encoder);
1993 return 0;
1994}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001995
1996/******************************************************************************
Ben Skeggseb6313a2013-02-11 09:52:58 +10001997 * PIOR
1998 *****************************************************************************/
1999
2000static void
2001nv50_pior_dpms(struct drm_encoder *encoder, int mode)
2002{
2003 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2004 struct nv50_disp *disp = nv50_disp(encoder->dev);
2005 u32 mthd = (nv_encoder->dcb->type << 12) | nv_encoder->or;
2006 u32 ctrl = (mode == DRM_MODE_DPMS_ON);
2007 nv_call(disp->core, NV50_DISP_PIOR_PWR + mthd, ctrl);
2008}
2009
2010static bool
2011nv50_pior_mode_fixup(struct drm_encoder *encoder,
2012 const struct drm_display_mode *mode,
2013 struct drm_display_mode *adjusted_mode)
2014{
2015 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2016 struct nouveau_connector *nv_connector;
2017
2018 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2019 if (nv_connector && nv_connector->native_mode) {
2020 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
2021 int id = adjusted_mode->base.id;
2022 *adjusted_mode = *nv_connector->native_mode;
2023 adjusted_mode->base.id = id;
2024 }
2025 }
2026
2027 adjusted_mode->clock *= 2;
2028 return true;
2029}
2030
2031static void
2032nv50_pior_commit(struct drm_encoder *encoder)
2033{
2034}
2035
2036static void
2037nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
2038 struct drm_display_mode *adjusted_mode)
2039{
2040 struct nv50_mast *mast = nv50_mast(encoder->dev);
2041 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2042 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
2043 struct nouveau_connector *nv_connector;
2044 u8 owner = 1 << nv_crtc->index;
2045 u8 proto, depth;
2046 u32 *push;
2047
2048 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2049 switch (nv_connector->base.display_info.bpc) {
2050 case 10: depth = 0x6; break;
2051 case 8: depth = 0x5; break;
2052 case 6: depth = 0x2; break;
2053 default: depth = 0x0; break;
2054 }
2055
2056 switch (nv_encoder->dcb->type) {
2057 case DCB_OUTPUT_TMDS:
2058 case DCB_OUTPUT_DP:
2059 proto = 0x0;
2060 break;
2061 default:
2062 BUG_ON(1);
2063 break;
2064 }
2065
2066 nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
2067
2068 push = evo_wait(mast, 8);
2069 if (push) {
2070 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
2071 u32 ctrl = (depth << 16) | (proto << 8) | owner;
2072 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2073 ctrl |= 0x00001000;
2074 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2075 ctrl |= 0x00002000;
2076 evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
2077 evo_data(push, ctrl);
2078 }
2079
2080 evo_kick(push, mast);
2081 }
2082
2083 nv_encoder->crtc = encoder->crtc;
2084}
2085
2086static void
2087nv50_pior_disconnect(struct drm_encoder *encoder)
2088{
2089 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2090 struct nv50_mast *mast = nv50_mast(encoder->dev);
2091 const int or = nv_encoder->or;
2092 u32 *push;
2093
2094 if (nv_encoder->crtc) {
2095 nv50_crtc_prepare(nv_encoder->crtc);
2096
2097 push = evo_wait(mast, 4);
2098 if (push) {
2099 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
2100 evo_mthd(push, 0x0700 + (or * 0x040), 1);
2101 evo_data(push, 0x00000000);
2102 }
Ben Skeggseb6313a2013-02-11 09:52:58 +10002103 evo_kick(push, mast);
2104 }
2105 }
2106
2107 nv_encoder->crtc = NULL;
2108}
2109
2110static void
2111nv50_pior_destroy(struct drm_encoder *encoder)
2112{
2113 drm_encoder_cleanup(encoder);
2114 kfree(encoder);
2115}
2116
2117static const struct drm_encoder_helper_funcs nv50_pior_hfunc = {
2118 .dpms = nv50_pior_dpms,
2119 .mode_fixup = nv50_pior_mode_fixup,
2120 .prepare = nv50_pior_disconnect,
2121 .commit = nv50_pior_commit,
2122 .mode_set = nv50_pior_mode_set,
2123 .disable = nv50_pior_disconnect,
2124 .get_crtc = nv50_display_crtc_get,
2125};
2126
2127static const struct drm_encoder_funcs nv50_pior_func = {
2128 .destroy = nv50_pior_destroy,
2129};
2130
2131static int
2132nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
2133{
2134 struct nouveau_drm *drm = nouveau_drm(connector->dev);
2135 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
2136 struct nouveau_i2c_port *ddc = NULL;
2137 struct nouveau_encoder *nv_encoder;
2138 struct drm_encoder *encoder;
2139 int type;
2140
2141 switch (dcbe->type) {
2142 case DCB_OUTPUT_TMDS:
2143 ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTDDC(dcbe->extdev));
2144 type = DRM_MODE_ENCODER_TMDS;
2145 break;
2146 case DCB_OUTPUT_DP:
2147 ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTAUX(dcbe->extdev));
2148 type = DRM_MODE_ENCODER_TMDS;
2149 break;
2150 default:
2151 return -ENODEV;
2152 }
2153
2154 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2155 if (!nv_encoder)
2156 return -ENOMEM;
2157 nv_encoder->dcb = dcbe;
2158 nv_encoder->or = ffs(dcbe->or) - 1;
2159 nv_encoder->i2c = ddc;
2160
2161 encoder = to_drm_encoder(nv_encoder);
2162 encoder->possible_crtcs = dcbe->heads;
2163 encoder->possible_clones = 0;
2164 drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type);
2165 drm_encoder_helper_add(encoder, &nv50_pior_hfunc);
2166
2167 drm_mode_connector_attach_encoder(connector, encoder);
2168 return 0;
2169}
2170
2171/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10002172 * Init
2173 *****************************************************************************/
Ben Skeggs2a44e492011-11-09 11:36:33 +10002174void
Ben Skeggse225f442012-11-21 14:40:21 +10002175nv50_display_fini(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002176{
Ben Skeggs26f6d882011-07-04 16:25:18 +10002177}
2178
2179int
Ben Skeggse225f442012-11-21 14:40:21 +10002180nv50_display_init(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002181{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002182 struct nv50_disp *disp = nv50_disp(dev);
2183 struct drm_crtc *crtc;
2184 u32 *push;
2185
2186 push = evo_wait(nv50_mast(dev), 32);
2187 if (!push)
2188 return -EBUSY;
2189
2190 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2191 struct nv50_sync *sync = nv50_sync(crtc);
2192 nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002193 }
2194
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002195 evo_mthd(push, 0x0088, 1);
2196 evo_data(push, NvEvoSync);
2197 evo_kick(push, nv50_mast(dev));
2198 return 0;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002199}
2200
2201void
Ben Skeggse225f442012-11-21 14:40:21 +10002202nv50_display_destroy(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002203{
Ben Skeggse225f442012-11-21 14:40:21 +10002204 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002205
Ben Skeggse225f442012-11-21 14:40:21 +10002206 nv50_dmac_destroy(disp->core, &disp->mast.base);
Ben Skeggsbdb8c212011-11-12 01:30:24 +10002207
Ben Skeggs816af2f2011-11-16 15:48:48 +10002208 nouveau_bo_unmap(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002209 if (disp->sync)
2210 nouveau_bo_unpin(disp->sync);
Ben Skeggs816af2f2011-11-16 15:48:48 +10002211 nouveau_bo_ref(NULL, &disp->sync);
Ben Skeggs51beb422011-07-05 10:33:08 +10002212
Ben Skeggs77145f12012-07-31 16:16:21 +10002213 nouveau_display(dev)->priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002214 kfree(disp);
2215}
2216
2217int
Ben Skeggse225f442012-11-21 14:40:21 +10002218nv50_display_create(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002219{
Ben Skeggs77145f12012-07-31 16:16:21 +10002220 struct nouveau_device *device = nouveau_dev(dev);
2221 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs77145f12012-07-31 16:16:21 +10002222 struct dcb_table *dcb = &drm->vbios.dcb;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002223 struct drm_connector *connector, *tmp;
Ben Skeggse225f442012-11-21 14:40:21 +10002224 struct nv50_disp *disp;
Ben Skeggscb75d972012-07-11 10:44:20 +10002225 struct dcb_output *dcbe;
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002226 int crtcs, ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002227
2228 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
2229 if (!disp)
2230 return -ENOMEM;
Ben Skeggs77145f12012-07-31 16:16:21 +10002231
2232 nouveau_display(dev)->priv = disp;
Ben Skeggse225f442012-11-21 14:40:21 +10002233 nouveau_display(dev)->dtor = nv50_display_destroy;
2234 nouveau_display(dev)->init = nv50_display_init;
2235 nouveau_display(dev)->fini = nv50_display_fini;
Ben Skeggs2332b312014-01-22 12:58:12 +10002236 disp->core = nouveau_display(dev)->core;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002237
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002238 /* small shared memory area we use for notifiers and semaphores */
2239 ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
2240 0, 0x0000, NULL, &disp->sync);
2241 if (!ret) {
2242 ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002243 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002244 ret = nouveau_bo_map(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002245 if (ret)
2246 nouveau_bo_unpin(disp->sync);
2247 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002248 if (ret)
2249 nouveau_bo_ref(NULL, &disp->sync);
2250 }
2251
2252 if (ret)
2253 goto out;
2254
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002255 /* allocate master evo channel */
Ben Skeggse225f442012-11-21 14:40:21 +10002256 ret = nv50_dmac_create(disp->core, NV50_DISP_MAST_CLASS, 0,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002257 &(struct nv50_display_mast_class) {
2258 .pushbuf = EVO_PUSH_HANDLE(MAST, 0),
2259 }, sizeof(struct nv50_display_mast_class),
2260 disp->sync->bo.offset, &disp->mast.base);
2261 if (ret)
2262 goto out;
2263
Ben Skeggs438d99e2011-07-05 16:48:06 +10002264 /* create crtc objects to represent the hw heads */
Ben Skeggs63718a02012-11-16 11:44:14 +10002265 if (nv_mclass(disp->core) >= NVD0_DISP_CLASS)
2266 crtcs = nv_rd32(device, 0x022448);
2267 else
2268 crtcs = 2;
2269
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002270 for (i = 0; i < crtcs; i++) {
Ben Skeggse225f442012-11-21 14:40:21 +10002271 ret = nv50_crtc_create(dev, disp->core, i);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002272 if (ret)
2273 goto out;
2274 }
2275
Ben Skeggs83fc0832011-07-05 13:08:40 +10002276 /* create encoder/connector objects based on VBIOS DCB table */
2277 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
2278 connector = nouveau_connector_create(dev, dcbe->connector);
2279 if (IS_ERR(connector))
2280 continue;
2281
Ben Skeggseb6313a2013-02-11 09:52:58 +10002282 if (dcbe->location == DCB_LOC_ON_CHIP) {
2283 switch (dcbe->type) {
2284 case DCB_OUTPUT_TMDS:
2285 case DCB_OUTPUT_LVDS:
2286 case DCB_OUTPUT_DP:
2287 ret = nv50_sor_create(connector, dcbe);
2288 break;
2289 case DCB_OUTPUT_ANALOG:
2290 ret = nv50_dac_create(connector, dcbe);
2291 break;
2292 default:
2293 ret = -ENODEV;
2294 break;
2295 }
2296 } else {
2297 ret = nv50_pior_create(connector, dcbe);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002298 }
2299
Ben Skeggseb6313a2013-02-11 09:52:58 +10002300 if (ret) {
2301 NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
2302 dcbe->location, dcbe->type,
2303 ffs(dcbe->or) - 1, ret);
Ben Skeggs94f54f52013-03-05 22:26:06 +10002304 ret = 0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002305 }
2306 }
2307
2308 /* cull any connectors we created that don't have an encoder */
2309 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
2310 if (connector->encoder_ids[0])
2311 continue;
2312
Ben Skeggs77145f12012-07-31 16:16:21 +10002313 NV_WARN(drm, "%s has no encoders, removing\n",
Jani Nikula8c6c3612014-06-03 14:56:18 +03002314 connector->name);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002315 connector->funcs->destroy(connector);
2316 }
2317
Ben Skeggs26f6d882011-07-04 16:25:18 +10002318out:
2319 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10002320 nv50_display_destroy(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002321 return ret;
2322}