blob: 794a20ea71fea7f2ca738043a9a4f48692913fff [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>
Daniel Vetter3cb9ae42014-10-29 10:03:57 +010029#include <drm/drm_plane_helper.h>
Ben Skeggs48743222014-05-31 01:48:06 +100030#include <drm/drm_dp_helper.h>
Ben Skeggs26f6d882011-07-04 16:25:18 +100031
Ben Skeggsfdb751e2014-08-10 04:10:23 +100032#include <nvif/class.h>
33
Ben Skeggs77145f12012-07-31 16:16:21 +100034#include "nouveau_drm.h"
35#include "nouveau_dma.h"
36#include "nouveau_gem.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100037#include "nouveau_connector.h"
38#include "nouveau_encoder.h"
39#include "nouveau_crtc.h"
Ben Skeggsf589be82012-07-22 11:55:54 +100040#include "nouveau_fence.h"
Ben Skeggs3a89cd02011-07-07 10:47:10 +100041#include "nv50_display.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100042
Ben Skeggs8a464382011-11-12 23:52:07 +100043#define EVO_DMA_NR 9
44
Ben Skeggsbdb8c212011-11-12 01:30:24 +100045#define EVO_MASTER (0x00)
Ben Skeggsa63a97e2011-11-16 15:22:34 +100046#define EVO_FLIP(c) (0x01 + (c))
Ben Skeggs8a464382011-11-12 23:52:07 +100047#define EVO_OVLY(c) (0x05 + (c))
48#define EVO_OIMM(c) (0x09 + (c))
Ben Skeggsbdb8c212011-11-12 01:30:24 +100049#define EVO_CURS(c) (0x0d + (c))
50
Ben Skeggs816af2f2011-11-16 15:48:48 +100051/* offsets in shared sync bo of various structures */
52#define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +100053#define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
54#define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00)
55#define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10)
Ben Skeggs816af2f2011-11-16 15:48:48 +100056
Ben Skeggsb5a794b2012-10-16 14:18:32 +100057/******************************************************************************
58 * EVO channel
59 *****************************************************************************/
60
Ben Skeggse225f442012-11-21 14:40:21 +100061struct nv50_chan {
Ben Skeggs0ad72862014-08-10 04:10:22 +100062 struct nvif_object user;
Ben Skeggsa01ca782015-08-20 14:54:15 +100063 struct nvif_device *device;
Ben Skeggsb5a794b2012-10-16 14:18:32 +100064};
65
66static int
Ben Skeggsa01ca782015-08-20 14:54:15 +100067nv50_chan_create(struct nvif_device *device, struct nvif_object *disp,
68 const u32 *oclass, u8 head, void *data, u32 size,
69 struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +100070{
Ben Skeggs6af52892014-11-03 15:01:33 +100071 const u32 handle = (oclass[0] << 16) | head;
72 u32 sclass[8];
73 int ret, i;
74
Ben Skeggsa01ca782015-08-20 14:54:15 +100075 chan->device = device;
76
Ben Skeggs6af52892014-11-03 15:01:33 +100077 ret = nvif_object_sclass(disp, sclass, ARRAY_SIZE(sclass));
78 WARN_ON(ret > ARRAY_SIZE(sclass));
79 if (ret < 0)
80 return ret;
81
Ben Skeggs410f3ec2014-08-10 04:10:25 +100082 while (oclass[0]) {
Ben Skeggs6af52892014-11-03 15:01:33 +100083 for (i = 0; i < ARRAY_SIZE(sclass); i++) {
84 if (sclass[i] == oclass[0]) {
Ben Skeggsa01ca782015-08-20 14:54:15 +100085 ret = nvif_object_init(disp, handle, oclass[0],
86 data, size, &chan->user);
Ben Skeggs6af52892014-11-03 15:01:33 +100087 if (ret == 0)
88 nvif_object_map(&chan->user);
89 return ret;
90 }
Ben Skeggsb76f1522014-08-10 04:10:28 +100091 }
Ben Skeggs6af52892014-11-03 15:01:33 +100092 oclass++;
Ben Skeggs410f3ec2014-08-10 04:10:25 +100093 }
Ben Skeggs6af52892014-11-03 15:01:33 +100094
Ben Skeggs410f3ec2014-08-10 04:10:25 +100095 return -ENOSYS;
Ben Skeggsb5a794b2012-10-16 14:18:32 +100096}
97
98static void
Ben Skeggs0ad72862014-08-10 04:10:22 +100099nv50_chan_destroy(struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000100{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000101 nvif_object_fini(&chan->user);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000102}
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 Skeggs0ad72862014-08-10 04:10:22 +1000113nv50_pioc_destroy(struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000114{
Ben Skeggs0ad72862014-08-10 04:10:22 +1000115 nv50_chan_destroy(&pioc->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000116}
117
118static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000119nv50_pioc_create(struct nvif_device *device, struct nvif_object *disp,
120 const u32 *oclass, u8 head, void *data, u32 size,
121 struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000122{
Ben Skeggsa01ca782015-08-20 14:54:15 +1000123 return nv50_chan_create(device, disp, oclass, head, data, size,
124 &pioc->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000125}
126
127/******************************************************************************
128 * Cursor Immediate
129 *****************************************************************************/
130
131struct nv50_curs {
132 struct nv50_pioc base;
133};
134
135static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000136nv50_curs_create(struct nvif_device *device, struct nvif_object *disp,
137 int head, struct nv50_curs *curs)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000138{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000139 struct nv50_disp_cursor_v0 args = {
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000140 .head = head,
141 };
142 static const u32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000143 GK104_DISP_CURSOR,
144 GF110_DISP_CURSOR,
145 GT214_DISP_CURSOR,
146 G82_DISP_CURSOR,
147 NV50_DISP_CURSOR,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000148 0
149 };
150
Ben Skeggsa01ca782015-08-20 14:54:15 +1000151 return nv50_pioc_create(device, disp, oclass, head, &args, sizeof(args),
152 &curs->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000153}
154
155/******************************************************************************
156 * Overlay Immediate
157 *****************************************************************************/
158
159struct nv50_oimm {
160 struct nv50_pioc base;
161};
162
163static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000164nv50_oimm_create(struct nvif_device *device, struct nvif_object *disp,
165 int head, struct nv50_oimm *oimm)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000166{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000167 struct nv50_disp_cursor_v0 args = {
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000168 .head = head,
169 };
170 static const u32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000171 GK104_DISP_OVERLAY,
172 GF110_DISP_OVERLAY,
173 GT214_DISP_OVERLAY,
174 G82_DISP_OVERLAY,
175 NV50_DISP_OVERLAY,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000176 0
177 };
178
Ben Skeggsa01ca782015-08-20 14:54:15 +1000179 return nv50_pioc_create(device, disp, oclass, head, &args, sizeof(args),
180 &oimm->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000181}
182
183/******************************************************************************
184 * DMA EVO channel
185 *****************************************************************************/
186
Ben Skeggse225f442012-11-21 14:40:21 +1000187struct nv50_dmac {
188 struct nv50_chan base;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000189 dma_addr_t handle;
190 u32 *ptr;
Daniel Vetter59ad1462012-12-02 14:49:44 +0100191
Ben Skeggs0ad72862014-08-10 04:10:22 +1000192 struct nvif_object sync;
193 struct nvif_object vram;
194
Daniel Vetter59ad1462012-12-02 14:49:44 +0100195 /* Protects against concurrent pushbuf access to this channel, lock is
196 * grabbed by evo_wait (if the pushbuf reservation is successful) and
197 * dropped again by evo_kick. */
198 struct mutex lock;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000199};
200
201static void
Ben Skeggs0ad72862014-08-10 04:10:22 +1000202nv50_dmac_destroy(struct nv50_dmac *dmac, struct nvif_object *disp)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000203{
Ben Skeggsa01ca782015-08-20 14:54:15 +1000204 struct nvif_device *device = dmac->base.device;
205
Ben Skeggs0ad72862014-08-10 04:10:22 +1000206 nvif_object_fini(&dmac->vram);
207 nvif_object_fini(&dmac->sync);
208
209 nv50_chan_destroy(&dmac->base);
210
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000211 if (dmac->ptr) {
Ben Skeggsa01ca782015-08-20 14:54:15 +1000212 struct pci_dev *pdev = nvxx_device(device)->pdev;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000213 pci_free_consistent(pdev, PAGE_SIZE, dmac->ptr, dmac->handle);
214 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000215}
216
217static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000218nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp,
219 const u32 *oclass, u8 head, void *data, u32 size, u64 syncbuf,
Ben Skeggse225f442012-11-21 14:40:21 +1000220 struct nv50_dmac *dmac)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000221{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000222 struct nv50_disp_core_channel_dma_v0 *args = data;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000223 struct nvif_object pushbuf;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000224 int ret;
225
Daniel Vetter59ad1462012-12-02 14:49:44 +0100226 mutex_init(&dmac->lock);
227
Ben Skeggs989aa5b2015-01-12 12:33:37 +1000228 dmac->ptr = pci_alloc_consistent(nvxx_device(device)->pdev,
Ben Skeggs0ad72862014-08-10 04:10:22 +1000229 PAGE_SIZE, &dmac->handle);
Ben Skeggs47057302012-11-16 13:58:48 +1000230 if (!dmac->ptr)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000231 return -ENOMEM;
232
Ben Skeggsa01ca782015-08-20 14:54:15 +1000233 ret = nvif_object_init(&device->object, args->pushbuf,
234 NV_DMA_FROM_MEMORY, &(struct nv_dma_v0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +1000235 .target = NV_DMA_V0_TARGET_PCI_US,
236 .access = NV_DMA_V0_ACCESS_RD,
Ben Skeggs47057302012-11-16 13:58:48 +1000237 .start = dmac->handle + 0x0000,
238 .limit = dmac->handle + 0x0fff,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000239 }, sizeof(struct nv_dma_v0), &pushbuf);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000240 if (ret)
241 return ret;
242
Ben Skeggsa01ca782015-08-20 14:54:15 +1000243 ret = nv50_chan_create(device, disp, oclass, head, data, size,
244 &dmac->base);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000245 nvif_object_fini(&pushbuf);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000246 if (ret)
247 return ret;
248
Ben Skeggsa01ca782015-08-20 14:54:15 +1000249 ret = nvif_object_init(&dmac->base.user, 0xf0000000, NV_DMA_IN_MEMORY,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000250 &(struct nv_dma_v0) {
251 .target = NV_DMA_V0_TARGET_VRAM,
252 .access = NV_DMA_V0_ACCESS_RDWR,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000253 .start = syncbuf + 0x0000,
254 .limit = syncbuf + 0x0fff,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000255 }, sizeof(struct nv_dma_v0),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000256 &dmac->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000257 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000258 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000259
Ben Skeggsa01ca782015-08-20 14:54:15 +1000260 ret = nvif_object_init(&dmac->base.user, 0xf0000001, NV_DMA_IN_MEMORY,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000261 &(struct nv_dma_v0) {
262 .target = NV_DMA_V0_TARGET_VRAM,
263 .access = NV_DMA_V0_ACCESS_RDWR,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000264 .start = 0,
Ben Skeggsf392ec42014-08-10 04:10:28 +1000265 .limit = device->info.ram_user - 1,
Ben Skeggs4acfd702014-08-10 04:10:24 +1000266 }, sizeof(struct nv_dma_v0),
Ben Skeggs0ad72862014-08-10 04:10:22 +1000267 &dmac->vram);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000268 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000269 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000270
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000271 return ret;
272}
273
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000274/******************************************************************************
275 * Core
276 *****************************************************************************/
277
Ben Skeggse225f442012-11-21 14:40:21 +1000278struct nv50_mast {
279 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000280};
281
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000282static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000283nv50_core_create(struct nvif_device *device, struct nvif_object *disp,
284 u64 syncbuf, struct nv50_mast *core)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000285{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000286 struct nv50_disp_core_channel_dma_v0 args = {
287 .pushbuf = 0xb0007d00,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000288 };
289 static const u32 oclass[] = {
Ben Skeggsdbbd6bc2014-08-19 10:23:47 +1000290 GM204_DISP_CORE_CHANNEL_DMA,
Ben Skeggs648d4df2014-08-10 04:10:27 +1000291 GM107_DISP_CORE_CHANNEL_DMA,
292 GK110_DISP_CORE_CHANNEL_DMA,
293 GK104_DISP_CORE_CHANNEL_DMA,
294 GF110_DISP_CORE_CHANNEL_DMA,
295 GT214_DISP_CORE_CHANNEL_DMA,
296 GT206_DISP_CORE_CHANNEL_DMA,
297 GT200_DISP_CORE_CHANNEL_DMA,
298 G82_DISP_CORE_CHANNEL_DMA,
299 NV50_DISP_CORE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000300 0
301 };
302
Ben Skeggsa01ca782015-08-20 14:54:15 +1000303 return nv50_dmac_create(device, disp, oclass, 0, &args, sizeof(args),
304 syncbuf, &core->base);
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000305}
306
307/******************************************************************************
308 * Base
309 *****************************************************************************/
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000310
Ben Skeggse225f442012-11-21 14:40:21 +1000311struct nv50_sync {
312 struct nv50_dmac base;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000313 u32 addr;
314 u32 data;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000315};
316
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000317static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000318nv50_base_create(struct nvif_device *device, struct nvif_object *disp,
319 int head, u64 syncbuf, struct nv50_sync *base)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000320{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000321 struct nv50_disp_base_channel_dma_v0 args = {
322 .pushbuf = 0xb0007c00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000323 .head = head,
324 };
325 static const u32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000326 GK110_DISP_BASE_CHANNEL_DMA,
327 GK104_DISP_BASE_CHANNEL_DMA,
328 GF110_DISP_BASE_CHANNEL_DMA,
329 GT214_DISP_BASE_CHANNEL_DMA,
330 GT200_DISP_BASE_CHANNEL_DMA,
331 G82_DISP_BASE_CHANNEL_DMA,
332 NV50_DISP_BASE_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000333 0
334 };
335
Ben Skeggsa01ca782015-08-20 14:54:15 +1000336 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000337 syncbuf, &base->base);
338}
339
340/******************************************************************************
341 * Overlay
342 *****************************************************************************/
343
Ben Skeggse225f442012-11-21 14:40:21 +1000344struct nv50_ovly {
345 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000346};
Ben Skeggsf20ce962011-07-08 13:17:01 +1000347
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000348static int
Ben Skeggsa01ca782015-08-20 14:54:15 +1000349nv50_ovly_create(struct nvif_device *device, struct nvif_object *disp,
350 int head, u64 syncbuf, struct nv50_ovly *ovly)
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000351{
Ben Skeggs648d4df2014-08-10 04:10:27 +1000352 struct nv50_disp_overlay_channel_dma_v0 args = {
353 .pushbuf = 0xb0007e00 | head,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000354 .head = head,
355 };
356 static const u32 oclass[] = {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000357 GK104_DISP_OVERLAY_CONTROL_DMA,
358 GF110_DISP_OVERLAY_CONTROL_DMA,
359 GT214_DISP_OVERLAY_CHANNEL_DMA,
360 GT200_DISP_OVERLAY_CHANNEL_DMA,
361 G82_DISP_OVERLAY_CHANNEL_DMA,
362 NV50_DISP_OVERLAY_CHANNEL_DMA,
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000363 0
364 };
365
Ben Skeggsa01ca782015-08-20 14:54:15 +1000366 return nv50_dmac_create(device, disp, oclass, head, &args, sizeof(args),
Ben Skeggs410f3ec2014-08-10 04:10:25 +1000367 syncbuf, &ovly->base);
368}
Ben Skeggs26f6d882011-07-04 16:25:18 +1000369
Ben Skeggse225f442012-11-21 14:40:21 +1000370struct nv50_head {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000371 struct nouveau_crtc base;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000372 struct nouveau_bo *image;
Ben Skeggse225f442012-11-21 14:40:21 +1000373 struct nv50_curs curs;
374 struct nv50_sync sync;
375 struct nv50_ovly ovly;
376 struct nv50_oimm oimm;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000377};
378
Ben Skeggse225f442012-11-21 14:40:21 +1000379#define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
380#define nv50_curs(c) (&nv50_head(c)->curs)
381#define nv50_sync(c) (&nv50_head(c)->sync)
382#define nv50_ovly(c) (&nv50_head(c)->ovly)
383#define nv50_oimm(c) (&nv50_head(c)->oimm)
384#define nv50_chan(c) (&(c)->base.base)
Ben Skeggs0ad72862014-08-10 04:10:22 +1000385#define nv50_vers(c) nv50_chan(c)->user.oclass
386
387struct nv50_fbdma {
388 struct list_head head;
389 struct nvif_object core;
390 struct nvif_object base[4];
391};
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000392
Ben Skeggse225f442012-11-21 14:40:21 +1000393struct nv50_disp {
Ben Skeggs0ad72862014-08-10 04:10:22 +1000394 struct nvif_object *disp;
Ben Skeggse225f442012-11-21 14:40:21 +1000395 struct nv50_mast mast;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000396
Ben Skeggs8a423642014-08-10 04:10:19 +1000397 struct list_head fbdma;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000398
399 struct nouveau_bo *sync;
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000400};
401
Ben Skeggse225f442012-11-21 14:40:21 +1000402static struct nv50_disp *
403nv50_disp(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +1000404{
Ben Skeggs77145f12012-07-31 16:16:21 +1000405 return nouveau_display(dev)->priv;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000406}
407
Ben Skeggse225f442012-11-21 14:40:21 +1000408#define nv50_mast(d) (&nv50_disp(d)->mast)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000409
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000410static struct drm_crtc *
Ben Skeggse225f442012-11-21 14:40:21 +1000411nv50_display_crtc_get(struct drm_encoder *encoder)
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000412{
413 return nouveau_encoder(encoder)->crtc;
414}
415
416/******************************************************************************
417 * EVO channel helpers
418 *****************************************************************************/
Ben Skeggs51beb422011-07-05 10:33:08 +1000419static u32 *
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000420evo_wait(void *evoc, int nr)
Ben Skeggs51beb422011-07-05 10:33:08 +1000421{
Ben Skeggse225f442012-11-21 14:40:21 +1000422 struct nv50_dmac *dmac = evoc;
Ben Skeggsa01ca782015-08-20 14:54:15 +1000423 struct nvif_device *device = dmac->base.device;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000424 u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4;
Ben Skeggs51beb422011-07-05 10:33:08 +1000425
Daniel Vetter59ad1462012-12-02 14:49:44 +0100426 mutex_lock(&dmac->lock);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000427 if (put + nr >= (PAGE_SIZE / 4) - 8) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000428 dmac->ptr[put] = 0x20000000;
Ben Skeggs51beb422011-07-05 10:33:08 +1000429
Ben Skeggs0ad72862014-08-10 04:10:22 +1000430 nvif_wr32(&dmac->base.user, 0x0000, 0x00000000);
Ben Skeggs54442042015-08-20 14:54:11 +1000431 if (nvif_msec(device, 2000,
432 if (!nvif_rd32(&dmac->base.user, 0x0004))
433 break;
434 ) < 0) {
Daniel Vetter59ad1462012-12-02 14:49:44 +0100435 mutex_unlock(&dmac->lock);
Ben Skeggs9ad97ed2015-08-20 14:54:13 +1000436 printk(KERN_ERR "nouveau: evo channel stalled\n");
Ben Skeggs51beb422011-07-05 10:33:08 +1000437 return NULL;
438 }
439
440 put = 0;
441 }
442
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000443 return dmac->ptr + put;
Ben Skeggs51beb422011-07-05 10:33:08 +1000444}
445
446static void
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000447evo_kick(u32 *push, void *evoc)
Ben Skeggs51beb422011-07-05 10:33:08 +1000448{
Ben Skeggse225f442012-11-21 14:40:21 +1000449 struct nv50_dmac *dmac = evoc;
Ben Skeggs0ad72862014-08-10 04:10:22 +1000450 nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
Daniel Vetter59ad1462012-12-02 14:49:44 +0100451 mutex_unlock(&dmac->lock);
Ben Skeggs51beb422011-07-05 10:33:08 +1000452}
453
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000454#if 1
Ben Skeggs51beb422011-07-05 10:33:08 +1000455#define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
456#define evo_data(p,d) *((p)++) = (d)
Ben Skeggs2b1930c2014-11-03 16:43:59 +1000457#else
458#define evo_mthd(p,m,s) do { \
459 const u32 _m = (m), _s = (s); \
460 printk(KERN_ERR "%04x %d %s\n", _m, _s, __func__); \
461 *((p)++) = ((_s << 18) | _m); \
462} while(0)
463#define evo_data(p,d) do { \
464 const u32 _d = (d); \
465 printk(KERN_ERR "\t%08x\n", _d); \
466 *((p)++) = _d; \
467} while(0)
468#endif
Ben Skeggs51beb422011-07-05 10:33:08 +1000469
Ben Skeggs3376ee32011-11-12 14:28:12 +1000470static bool
471evo_sync_wait(void *data)
472{
Ben Skeggs5cc027f2013-02-18 17:50:51 -0500473 if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
474 return true;
475 usleep_range(1, 2);
476 return false;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000477}
478
479static int
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000480evo_sync(struct drm_device *dev)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000481{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000482 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggse225f442012-11-21 14:40:21 +1000483 struct nv50_disp *disp = nv50_disp(dev);
484 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000485 u32 *push = evo_wait(mast, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000486 if (push) {
Ben Skeggs816af2f2011-11-16 15:48:48 +1000487 nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000488 evo_mthd(push, 0x0084, 1);
Ben Skeggs816af2f2011-11-16 15:48:48 +1000489 evo_data(push, 0x80000000 | EVO_MAST_NTFY);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000490 evo_mthd(push, 0x0080, 2);
491 evo_data(push, 0x00000000);
492 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000493 evo_kick(push, mast);
Ben Skeggs54442042015-08-20 14:54:11 +1000494 if (nvif_msec(device, 2000,
495 if (evo_sync_wait(disp->sync))
496 break;
497 ) >= 0)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000498 return 0;
499 }
500
501 return -EBUSY;
502}
503
504/******************************************************************************
Ben Skeggsa63a97e2011-11-16 15:22:34 +1000505 * Page flipping channel
Ben Skeggs3376ee32011-11-12 14:28:12 +1000506 *****************************************************************************/
507struct nouveau_bo *
Ben Skeggse225f442012-11-21 14:40:21 +1000508nv50_display_crtc_sema(struct drm_device *dev, int crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000509{
Ben Skeggse225f442012-11-21 14:40:21 +1000510 return nv50_disp(dev)->sync;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000511}
512
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000513struct nv50_display_flip {
514 struct nv50_disp *disp;
515 struct nv50_sync *chan;
516};
517
518static bool
519nv50_display_flip_wait(void *data)
520{
521 struct nv50_display_flip *flip = data;
522 if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) ==
Calvin Owensb1ea3e62013-04-07 21:01:19 -0500523 flip->chan->data)
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000524 return true;
525 usleep_range(1, 2);
526 return false;
527}
528
Ben Skeggs3376ee32011-11-12 14:28:12 +1000529void
Ben Skeggse225f442012-11-21 14:40:21 +1000530nv50_display_flip_stop(struct drm_crtc *crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000531{
Ben Skeggs967e7bd2014-08-10 04:10:22 +1000532 struct nvif_device *device = &nouveau_drm(crtc->dev)->device;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000533 struct nv50_display_flip flip = {
534 .disp = nv50_disp(crtc->dev),
535 .chan = nv50_sync(crtc),
536 };
Ben Skeggs3376ee32011-11-12 14:28:12 +1000537 u32 *push;
538
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000539 push = evo_wait(flip.chan, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000540 if (push) {
541 evo_mthd(push, 0x0084, 1);
542 evo_data(push, 0x00000000);
543 evo_mthd(push, 0x0094, 1);
544 evo_data(push, 0x00000000);
545 evo_mthd(push, 0x00c0, 1);
546 evo_data(push, 0x00000000);
547 evo_mthd(push, 0x0080, 1);
548 evo_data(push, 0x00000000);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000549 evo_kick(push, flip.chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000550 }
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000551
Ben Skeggs54442042015-08-20 14:54:11 +1000552 nvif_msec(device, 2000,
553 if (nv50_display_flip_wait(&flip))
554 break;
555 );
Ben Skeggs3376ee32011-11-12 14:28:12 +1000556}
557
558int
Ben Skeggse225f442012-11-21 14:40:21 +1000559nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Ben Skeggs3376ee32011-11-12 14:28:12 +1000560 struct nouveau_channel *chan, u32 swap_interval)
561{
562 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000563 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000564 struct nv50_head *head = nv50_head(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000565 struct nv50_sync *sync = nv50_sync(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000566 u32 *push;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000567 int ret;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000568
Ben Skeggs9ba83102014-12-22 19:50:23 +1000569 if (crtc->primary->fb->width != fb->width ||
570 crtc->primary->fb->height != fb->height)
571 return -EINVAL;
572
Ben Skeggs3376ee32011-11-12 14:28:12 +1000573 swap_interval <<= 4;
574 if (swap_interval == 0)
575 swap_interval |= 0x100;
Ben Skeggsf60b6e72013-03-19 15:20:00 +1000576 if (chan == NULL)
577 evo_sync(crtc->dev);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000578
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000579 push = evo_wait(sync, 128);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000580 if (unlikely(push == NULL))
581 return -EBUSY;
582
Ben Skeggsa01ca782015-08-20 14:54:15 +1000583 if (chan && chan->user.oclass < G82_CHANNEL_GPFIFO) {
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000584 ret = RING_SPACE(chan, 8);
585 if (ret)
586 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000587
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000588 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000589 OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000590 OUT_RING (chan, sync->addr ^ 0x10);
591 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
592 OUT_RING (chan, sync->data + 1);
593 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
594 OUT_RING (chan, sync->addr);
595 OUT_RING (chan, sync->data);
596 } else
Ben Skeggsa01ca782015-08-20 14:54:15 +1000597 if (chan && chan->user.oclass < FERMI_CHANNEL_GPFIFO) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000598 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000599 ret = RING_SPACE(chan, 12);
600 if (ret)
601 return ret;
Ben Skeggsa34caf72013-02-14 09:28:37 +1000602
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000603 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
Ben Skeggs0ad72862014-08-10 04:10:22 +1000604 OUT_RING (chan, chan->vram.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000605 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
606 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
607 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
608 OUT_RING (chan, sync->data + 1);
609 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
610 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
611 OUT_RING (chan, upper_32_bits(addr));
612 OUT_RING (chan, lower_32_bits(addr));
613 OUT_RING (chan, sync->data);
614 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
615 } else
616 if (chan) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000617 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000618 ret = RING_SPACE(chan, 10);
619 if (ret)
620 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000621
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000622 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
623 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
624 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
625 OUT_RING (chan, sync->data + 1);
626 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
627 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
628 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
629 OUT_RING (chan, upper_32_bits(addr));
630 OUT_RING (chan, lower_32_bits(addr));
631 OUT_RING (chan, sync->data);
632 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
633 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
634 }
Ben Skeggs35bcf5d2012-04-30 11:34:10 -0500635
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000636 if (chan) {
637 sync->addr ^= 0x10;
638 sync->data++;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000639 FIRE_RING (chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000640 }
641
642 /* queue the flip */
643 evo_mthd(push, 0x0100, 1);
644 evo_data(push, 0xfffe0000);
645 evo_mthd(push, 0x0084, 1);
646 evo_data(push, swap_interval);
647 if (!(swap_interval & 0x00000100)) {
648 evo_mthd(push, 0x00e0, 1);
649 evo_data(push, 0x40000000);
650 }
651 evo_mthd(push, 0x0088, 4);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000652 evo_data(push, sync->addr);
653 evo_data(push, sync->data++);
654 evo_data(push, sync->data);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000655 evo_data(push, sync->base.sync.handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000656 evo_mthd(push, 0x00a0, 2);
657 evo_data(push, 0x00000000);
658 evo_data(push, 0x00000000);
659 evo_mthd(push, 0x00c0, 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000660 evo_data(push, nv_fb->r_handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000661 evo_mthd(push, 0x0110, 2);
662 evo_data(push, 0x00000000);
663 evo_data(push, 0x00000000);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000664 if (nv50_vers(sync) < GF110_DISP_BASE_CHANNEL_DMA) {
Ben Skeggsed5085a52012-11-16 13:16:51 +1000665 evo_mthd(push, 0x0800, 5);
666 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
667 evo_data(push, 0);
668 evo_data(push, (fb->height << 16) | fb->width);
669 evo_data(push, nv_fb->r_pitch);
670 evo_data(push, nv_fb->r_format);
671 } else {
672 evo_mthd(push, 0x0400, 5);
673 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
674 evo_data(push, 0);
675 evo_data(push, (fb->height << 16) | fb->width);
676 evo_data(push, nv_fb->r_pitch);
677 evo_data(push, nv_fb->r_format);
678 }
Ben Skeggs3376ee32011-11-12 14:28:12 +1000679 evo_mthd(push, 0x0080, 1);
680 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000681 evo_kick(push, sync);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000682
683 nouveau_bo_ref(nv_fb->nvbo, &head->image);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000684 return 0;
685}
686
Ben Skeggs26f6d882011-07-04 16:25:18 +1000687/******************************************************************************
Ben Skeggs438d99e2011-07-05 16:48:06 +1000688 * CRTC
689 *****************************************************************************/
690static int
Ben Skeggse225f442012-11-21 14:40:21 +1000691nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000692{
Ben Skeggse225f442012-11-21 14:40:21 +1000693 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde691852011-10-17 12:23:41 +1000694 struct nouveau_connector *nv_connector;
695 struct drm_connector *connector;
696 u32 *push, mode = 0x00;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000697
Ben Skeggs488ff202011-10-17 10:38:10 +1000698 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggsde691852011-10-17 12:23:41 +1000699 connector = &nv_connector->base;
700 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
Matt Roperf4510a22014-04-01 15:22:40 -0700701 if (nv_crtc->base.primary->fb->depth > connector->display_info.bpc * 3)
Ben Skeggsde691852011-10-17 12:23:41 +1000702 mode = DITHERING_MODE_DYNAMIC2X2;
703 } else {
704 mode = nv_connector->dithering_mode;
705 }
706
707 if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
708 if (connector->display_info.bpc >= 8)
709 mode |= DITHERING_DEPTH_8BPC;
710 } else {
711 mode |= nv_connector->dithering_depth;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000712 }
713
Ben Skeggsde8268c2012-11-16 10:24:31 +1000714 push = evo_wait(mast, 4);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000715 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000716 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000717 evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1);
718 evo_data(push, mode);
719 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000720 if (nv50_vers(mast) < GK104_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000721 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1);
722 evo_data(push, mode);
723 } else {
724 evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1);
725 evo_data(push, mode);
726 }
727
Ben Skeggs438d99e2011-07-05 16:48:06 +1000728 if (update) {
729 evo_mthd(push, 0x0080, 1);
730 evo_data(push, 0x00000000);
731 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000732 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000733 }
734
735 return 0;
736}
737
738static int
Ben Skeggse225f442012-11-21 14:40:21 +1000739nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000740{
Ben Skeggse225f442012-11-21 14:40:21 +1000741 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs92854622011-11-11 23:49:06 +1000742 struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000743 struct drm_crtc *crtc = &nv_crtc->base;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000744 struct nouveau_connector *nv_connector;
Ben Skeggs92854622011-11-11 23:49:06 +1000745 int mode = DRM_MODE_SCALE_NONE;
746 u32 oX, oY, *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000747
Ben Skeggs92854622011-11-11 23:49:06 +1000748 /* start off at the resolution we programmed the crtc for, this
749 * effectively handles NONE/FULL scaling
750 */
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000751 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggs576f7912014-12-22 17:19:26 +1000752 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs92854622011-11-11 23:49:06 +1000753 mode = nv_connector->scaling_mode;
Ben Skeggs576f7912014-12-22 17:19:26 +1000754 if (nv_connector->scaling_full) /* non-EDID LVDS/eDP mode */
755 mode = DRM_MODE_SCALE_FULLSCREEN;
756 }
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000757
Ben Skeggs92854622011-11-11 23:49:06 +1000758 if (mode != DRM_MODE_SCALE_NONE)
759 omode = nv_connector->native_mode;
760 else
761 omode = umode;
762
763 oX = omode->hdisplay;
764 oY = omode->vdisplay;
765 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
766 oY *= 2;
767
768 /* add overscan compensation if necessary, will keep the aspect
769 * ratio the same as the backend mode unless overridden by the
770 * user setting both hborder and vborder properties.
771 */
772 if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
773 (nv_connector->underscan == UNDERSCAN_AUTO &&
774 nv_connector->edid &&
775 drm_detect_hdmi_monitor(nv_connector->edid)))) {
776 u32 bX = nv_connector->underscan_hborder;
777 u32 bY = nv_connector->underscan_vborder;
778 u32 aspect = (oY << 19) / oX;
779
780 if (bX) {
781 oX -= (bX * 2);
782 if (bY) oY -= (bY * 2);
783 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
784 } else {
785 oX -= (oX >> 4) + 32;
786 if (bY) oY -= (bY * 2);
787 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000788 }
789 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000790
Ben Skeggs92854622011-11-11 23:49:06 +1000791 /* handle CENTER/ASPECT scaling, taking into account the areas
792 * removed already for overscan compensation
793 */
794 switch (mode) {
795 case DRM_MODE_SCALE_CENTER:
796 oX = min((u32)umode->hdisplay, oX);
797 oY = min((u32)umode->vdisplay, oY);
798 /* fall-through */
799 case DRM_MODE_SCALE_ASPECT:
800 if (oY < oX) {
801 u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
802 oX = ((oY * aspect) + (aspect / 2)) >> 19;
803 } else {
804 u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
805 oY = ((oX * aspect) + (aspect / 2)) >> 19;
806 }
807 break;
808 default:
809 break;
810 }
811
Ben Skeggsde8268c2012-11-16 10:24:31 +1000812 push = evo_wait(mast, 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000813 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000814 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000815 /*XXX: SCALE_CTRL_ACTIVE??? */
816 evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2);
817 evo_data(push, (oY << 16) | oX);
818 evo_data(push, (oY << 16) | oX);
819 evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1);
820 evo_data(push, 0x00000000);
821 evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1);
822 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
823 } else {
824 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
825 evo_data(push, (oY << 16) | oX);
826 evo_data(push, (oY << 16) | oX);
827 evo_data(push, (oY << 16) | oX);
828 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
829 evo_data(push, 0x00000000);
830 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
831 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
832 }
833
834 evo_kick(push, mast);
835
Ben Skeggs3376ee32011-11-12 14:28:12 +1000836 if (update) {
Ben Skeggse225f442012-11-21 14:40:21 +1000837 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -0700838 nv50_display_flip_next(crtc, crtc->primary->fb,
839 NULL, 1);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000840 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000841 }
842
843 return 0;
844}
845
846static int
Roy Splieteae73822014-10-30 22:57:45 +0100847nv50_crtc_set_raster_vblank_dmi(struct nouveau_crtc *nv_crtc, u32 usec)
848{
849 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
850 u32 *push;
851
852 push = evo_wait(mast, 8);
853 if (!push)
854 return -ENOMEM;
855
856 evo_mthd(push, 0x0828 + (nv_crtc->index * 0x400), 1);
857 evo_data(push, usec);
858 evo_kick(push, mast);
859 return 0;
860}
861
862static int
Ben Skeggse225f442012-11-21 14:40:21 +1000863nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggsf9887d02012-11-21 13:03:42 +1000864{
Ben Skeggse225f442012-11-21 14:40:21 +1000865 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsf9887d02012-11-21 13:03:42 +1000866 u32 *push, hue, vib;
867 int adj;
868
869 adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
870 vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
871 hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
872
873 push = evo_wait(mast, 16);
874 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000875 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsf9887d02012-11-21 13:03:42 +1000876 evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1);
877 evo_data(push, (hue << 20) | (vib << 8));
878 } else {
879 evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1);
880 evo_data(push, (hue << 20) | (vib << 8));
881 }
882
883 if (update) {
884 evo_mthd(push, 0x0080, 1);
885 evo_data(push, 0x00000000);
886 }
887 evo_kick(push, mast);
888 }
889
890 return 0;
891}
892
893static int
Ben Skeggse225f442012-11-21 14:40:21 +1000894nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000895 int x, int y, bool update)
896{
897 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
Ben Skeggse225f442012-11-21 14:40:21 +1000898 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000899 u32 *push;
900
Ben Skeggsde8268c2012-11-16 10:24:31 +1000901 push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000902 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000903 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000904 evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1);
905 evo_data(push, nvfb->nvbo->bo.offset >> 8);
906 evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3);
907 evo_data(push, (fb->height << 16) | fb->width);
908 evo_data(push, nvfb->r_pitch);
909 evo_data(push, nvfb->r_format);
910 evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1);
911 evo_data(push, (y << 16) | x);
Ben Skeggs648d4df2014-08-10 04:10:27 +1000912 if (nv50_vers(mast) > NV50_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000913 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000914 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000915 }
916 } else {
917 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
918 evo_data(push, nvfb->nvbo->bo.offset >> 8);
919 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
920 evo_data(push, (fb->height << 16) | fb->width);
921 evo_data(push, nvfb->r_pitch);
922 evo_data(push, nvfb->r_format);
Ben Skeggs8a423642014-08-10 04:10:19 +1000923 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000924 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
925 evo_data(push, (y << 16) | x);
926 }
927
Ben Skeggsa46232e2011-07-07 15:23:48 +1000928 if (update) {
929 evo_mthd(push, 0x0080, 1);
930 evo_data(push, 0x00000000);
931 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000932 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000933 }
934
Ben Skeggs8a423642014-08-10 04:10:19 +1000935 nv_crtc->fb.handle = nvfb->r_handle;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000936 return 0;
937}
938
939static void
Ben Skeggse225f442012-11-21 14:40:21 +1000940nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000941{
Ben Skeggse225f442012-11-21 14:40:21 +1000942 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000943 u32 *push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000944 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000945 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000946 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
947 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100948 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000949 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000950 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000951 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
952 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100953 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000954 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000955 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000956 } else {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000957 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
958 evo_data(push, 0x85000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100959 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000960 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +1000961 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000962 }
963 evo_kick(push, mast);
964 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100965 nv_crtc->cursor.visible = true;
Ben Skeggsde8268c2012-11-16 10:24:31 +1000966}
967
968static void
Ben Skeggse225f442012-11-21 14:40:21 +1000969nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000970{
Ben Skeggse225f442012-11-21 14:40:21 +1000971 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000972 u32 *push = evo_wait(mast, 16);
973 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +1000974 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000975 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
976 evo_data(push, 0x05000000);
977 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +1000978 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000979 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
980 evo_data(push, 0x05000000);
981 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
982 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000983 } else {
984 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
985 evo_data(push, 0x05000000);
986 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
987 evo_data(push, 0x00000000);
988 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000989 evo_kick(push, mast);
990 }
Maarten Lankhorst4dc63932015-01-13 09:18:49 +0100991 nv_crtc->cursor.visible = false;
Ben Skeggsde8268c2012-11-16 10:24:31 +1000992}
Ben Skeggs438d99e2011-07-05 16:48:06 +1000993
Ben Skeggsde8268c2012-11-16 10:24:31 +1000994static void
Ben Skeggse225f442012-11-21 14:40:21 +1000995nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000996{
Ben Skeggse225f442012-11-21 14:40:21 +1000997 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000998
Ben Skeggs697bb722015-07-28 17:20:57 +1000999 if (show && nv_crtc->cursor.nvbo && nv_crtc->base.enabled)
Ben Skeggse225f442012-11-21 14:40:21 +10001000 nv50_crtc_cursor_show(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001001 else
Ben Skeggse225f442012-11-21 14:40:21 +10001002 nv50_crtc_cursor_hide(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001003
1004 if (update) {
1005 u32 *push = evo_wait(mast, 2);
1006 if (push) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001007 evo_mthd(push, 0x0080, 1);
1008 evo_data(push, 0x00000000);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001009 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001010 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001011 }
1012}
1013
1014static void
Ben Skeggse225f442012-11-21 14:40:21 +10001015nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001016{
1017}
1018
1019static void
Ben Skeggse225f442012-11-21 14:40:21 +10001020nv50_crtc_prepare(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001021{
1022 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001023 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001024 u32 *push;
1025
Ben Skeggse225f442012-11-21 14:40:21 +10001026 nv50_display_flip_stop(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +10001027
Ben Skeggs56d237d2014-05-19 14:54:33 +10001028 push = evo_wait(mast, 6);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001029 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001030 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001031 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1032 evo_data(push, 0x00000000);
1033 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1034 evo_data(push, 0x40000000);
1035 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001036 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001037 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
1038 evo_data(push, 0x00000000);
1039 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
1040 evo_data(push, 0x40000000);
1041 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
1042 evo_data(push, 0x00000000);
1043 } else {
1044 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
1045 evo_data(push, 0x00000000);
1046 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
1047 evo_data(push, 0x03000000);
1048 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
1049 evo_data(push, 0x00000000);
1050 }
1051
1052 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001053 }
1054
Ben Skeggse225f442012-11-21 14:40:21 +10001055 nv50_crtc_cursor_show_hide(nv_crtc, false, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001056}
1057
1058static void
Ben Skeggse225f442012-11-21 14:40:21 +10001059nv50_crtc_commit(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001060{
1061 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001062 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001063 u32 *push;
1064
Ben Skeggsde8268c2012-11-16 10:24:31 +10001065 push = evo_wait(mast, 32);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001066 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001067 if (nv50_vers(mast) < G82_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001068 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001069 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001070 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1071 evo_data(push, 0xc0000000);
1072 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1073 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10001074 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001075 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001076 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001077 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
1078 evo_data(push, 0xc0000000);
1079 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1080 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001081 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001082 } else {
1083 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +10001084 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001085 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
1086 evo_data(push, 0x83000000);
1087 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
1088 evo_data(push, 0x00000000);
1089 evo_data(push, 0x00000000);
1090 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10001091 evo_data(push, mast->base.vram.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001092 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
1093 evo_data(push, 0xffffff00);
1094 }
1095
1096 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001097 }
1098
Ben Skeggs5a560252014-11-10 15:52:02 +10001099 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Matt Roperf4510a22014-04-01 15:22:40 -07001100 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001101}
1102
1103static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001104nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001105 struct drm_display_mode *adjusted_mode)
1106{
Ben Skeggseb2e9682014-01-24 10:13:23 +10001107 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001108 return true;
1109}
1110
1111static int
Ben Skeggse225f442012-11-21 14:40:21 +10001112nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001113{
Matt Roperf4510a22014-04-01 15:22:40 -07001114 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001115 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001116 int ret;
1117
Ben Skeggs547ad072014-11-10 12:35:06 +10001118 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001119 if (ret == 0) {
1120 if (head->image)
1121 nouveau_bo_unpin(head->image);
1122 nouveau_bo_ref(nvfb->nvbo, &head->image);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001123 }
1124
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001125 return ret;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001126}
1127
1128static int
Ben Skeggse225f442012-11-21 14:40:21 +10001129nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001130 struct drm_display_mode *mode, int x, int y,
1131 struct drm_framebuffer *old_fb)
1132{
Ben Skeggse225f442012-11-21 14:40:21 +10001133 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001134 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1135 struct nouveau_connector *nv_connector;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001136 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
1137 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
1138 u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
1139 u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
Roy Spliet1dce6262014-09-12 18:00:13 +02001140 u32 vblan2e = 0, vblan2s = 1, vblankus = 0;
Ben Skeggs3488c572012-03-12 11:42:20 +10001141 u32 *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001142 int ret;
1143
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001144 hactive = mode->htotal;
1145 hsynce = mode->hsync_end - mode->hsync_start - 1;
1146 hbackp = mode->htotal - mode->hsync_end;
1147 hblanke = hsynce + hbackp;
1148 hfrontp = mode->hsync_start - mode->hdisplay;
1149 hblanks = mode->htotal - hfrontp - 1;
1150
1151 vactive = mode->vtotal * vscan / ilace;
1152 vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
1153 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
1154 vblanke = vsynce + vbackp;
1155 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
1156 vblanks = vactive - vfrontp - 1;
Roy Spliet1dce6262014-09-12 18:00:13 +02001157 /* XXX: Safe underestimate, even "0" works */
1158 vblankus = (vactive - mode->vdisplay - 2) * hactive;
1159 vblankus *= 1000;
1160 vblankus /= mode->clock;
1161
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001162 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1163 vblan2e = vactive + vsynce + vbackp;
1164 vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
1165 vactive = (vactive * 2) + 1;
Ben Skeggs2d1d8982011-11-11 23:39:22 +10001166 }
1167
Ben Skeggse225f442012-11-21 14:40:21 +10001168 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001169 if (ret)
1170 return ret;
1171
Ben Skeggsde8268c2012-11-16 10:24:31 +10001172 push = evo_wait(mast, 64);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001173 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001174 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001175 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
1176 evo_data(push, 0x00800000 | mode->clock);
1177 evo_data(push, (ilace == 2) ? 2 : 0);
Roy Splieteae73822014-10-30 22:57:45 +01001178 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001179 evo_data(push, 0x00000000);
1180 evo_data(push, (vactive << 16) | hactive);
1181 evo_data(push, ( vsynce << 16) | hsynce);
1182 evo_data(push, (vblanke << 16) | hblanke);
1183 evo_data(push, (vblanks << 16) | hblanks);
1184 evo_data(push, (vblan2e << 16) | vblan2s);
Roy Splieteae73822014-10-30 22:57:45 +01001185 evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1);
Ben Skeggsde8268c2012-11-16 10:24:31 +10001186 evo_data(push, 0x00000000);
1187 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
1188 evo_data(push, 0x00000311);
1189 evo_data(push, 0x00000100);
1190 } else {
1191 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
1192 evo_data(push, 0x00000000);
1193 evo_data(push, (vactive << 16) | hactive);
1194 evo_data(push, ( vsynce << 16) | hsynce);
1195 evo_data(push, (vblanke << 16) | hblanke);
1196 evo_data(push, (vblanks << 16) | hblanks);
1197 evo_data(push, (vblan2e << 16) | vblan2s);
1198 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
1199 evo_data(push, 0x00000000); /* ??? */
1200 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
1201 evo_data(push, mode->clock * 1000);
1202 evo_data(push, 0x00200000); /* ??? */
1203 evo_data(push, mode->clock * 1000);
1204 evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
1205 evo_data(push, 0x00000311);
1206 evo_data(push, 0x00000100);
1207 }
1208
1209 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001210 }
1211
1212 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001213 nv50_crtc_set_dither(nv_crtc, false);
1214 nv50_crtc_set_scale(nv_crtc, false);
Roy Splieteae73822014-10-30 22:57:45 +01001215
1216 /* G94 only accepts this after setting scale */
1217 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA)
1218 nv50_crtc_set_raster_vblank_dmi(nv_crtc, vblankus);
1219
Ben Skeggse225f442012-11-21 14:40:21 +10001220 nv50_crtc_set_color_vibrance(nv_crtc, false);
Matt Roperf4510a22014-04-01 15:22:40 -07001221 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001222 return 0;
1223}
1224
1225static int
Ben Skeggse225f442012-11-21 14:40:21 +10001226nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001227 struct drm_framebuffer *old_fb)
1228{
Ben Skeggs77145f12012-07-31 16:16:21 +10001229 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001230 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1231 int ret;
1232
Matt Roperf4510a22014-04-01 15:22:40 -07001233 if (!crtc->primary->fb) {
Ben Skeggs77145f12012-07-31 16:16:21 +10001234 NV_DEBUG(drm, "No FB bound\n");
Ben Skeggs84e2ad82011-08-26 09:40:39 +10001235 return 0;
1236 }
1237
Ben Skeggse225f442012-11-21 14:40:21 +10001238 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001239 if (ret)
1240 return ret;
1241
Ben Skeggse225f442012-11-21 14:40:21 +10001242 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -07001243 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
1244 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001245 return 0;
1246}
1247
1248static int
Ben Skeggse225f442012-11-21 14:40:21 +10001249nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001250 struct drm_framebuffer *fb, int x, int y,
1251 enum mode_set_atomic state)
1252{
1253 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001254 nv50_display_flip_stop(crtc);
1255 nv50_crtc_set_image(nv_crtc, fb, x, y, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001256 return 0;
1257}
1258
1259static void
Ben Skeggse225f442012-11-21 14:40:21 +10001260nv50_crtc_lut_load(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001261{
Ben Skeggse225f442012-11-21 14:40:21 +10001262 struct nv50_disp *disp = nv50_disp(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001263 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1264 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
1265 int i;
1266
1267 for (i = 0; i < 256; i++) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001268 u16 r = nv_crtc->lut.r[i] >> 2;
1269 u16 g = nv_crtc->lut.g[i] >> 2;
1270 u16 b = nv_crtc->lut.b[i] >> 2;
1271
Ben Skeggs648d4df2014-08-10 04:10:27 +10001272 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001273 writew(r + 0x0000, lut + (i * 0x08) + 0);
1274 writew(g + 0x0000, lut + (i * 0x08) + 2);
1275 writew(b + 0x0000, lut + (i * 0x08) + 4);
1276 } else {
1277 writew(r + 0x6000, lut + (i * 0x20) + 0);
1278 writew(g + 0x6000, lut + (i * 0x20) + 2);
1279 writew(b + 0x6000, lut + (i * 0x20) + 4);
1280 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001281 }
1282}
1283
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001284static void
1285nv50_crtc_disable(struct drm_crtc *crtc)
1286{
1287 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsefa366f2014-06-05 12:56:35 +10001288 evo_sync(crtc->dev);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001289 if (head->image)
1290 nouveau_bo_unpin(head->image);
1291 nouveau_bo_ref(NULL, &head->image);
1292}
1293
Ben Skeggs438d99e2011-07-05 16:48:06 +10001294static int
Ben Skeggse225f442012-11-21 14:40:21 +10001295nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001296 uint32_t handle, uint32_t width, uint32_t height)
1297{
1298 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1299 struct drm_device *dev = crtc->dev;
Ben Skeggs5a560252014-11-10 15:52:02 +10001300 struct drm_gem_object *gem = NULL;
1301 struct nouveau_bo *nvbo = NULL;
1302 int ret = 0;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001303
Ben Skeggs5a560252014-11-10 15:52:02 +10001304 if (handle) {
Ben Skeggs438d99e2011-07-05 16:48:06 +10001305 if (width != 64 || height != 64)
1306 return -EINVAL;
1307
1308 gem = drm_gem_object_lookup(dev, file_priv, handle);
1309 if (unlikely(!gem))
1310 return -ENOENT;
1311 nvbo = nouveau_gem_object(gem);
1312
Ben Skeggs5a560252014-11-10 15:52:02 +10001313 ret = nouveau_bo_pin(nvbo, TTM_PL_FLAG_VRAM, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001314 }
1315
Ben Skeggs5a560252014-11-10 15:52:02 +10001316 if (ret == 0) {
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001317 if (nv_crtc->cursor.nvbo)
1318 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1319 nouveau_bo_ref(nvbo, &nv_crtc->cursor.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001320 }
Ben Skeggs5a560252014-11-10 15:52:02 +10001321 drm_gem_object_unreference_unlocked(gem);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001322
Ben Skeggs5a560252014-11-10 15:52:02 +10001323 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001324 return ret;
1325}
1326
1327static int
Ben Skeggse225f442012-11-21 14:40:21 +10001328nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001329{
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001330 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001331 struct nv50_curs *curs = nv50_curs(crtc);
1332 struct nv50_chan *chan = nv50_chan(curs);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001333 nvif_wr32(&chan->user, 0x0084, (y << 16) | (x & 0xffff));
1334 nvif_wr32(&chan->user, 0x0080, 0x00000000);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001335
1336 nv_crtc->cursor_saved_x = x;
1337 nv_crtc->cursor_saved_y = y;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001338 return 0;
1339}
1340
1341static void
Ben Skeggse225f442012-11-21 14:40:21 +10001342nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001343 uint32_t start, uint32_t size)
1344{
1345 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Dan Carpenterbdefc8c2013-11-28 01:18:47 +03001346 u32 end = min_t(u32, start + size, 256);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001347 u32 i;
1348
1349 for (i = start; i < end; i++) {
1350 nv_crtc->lut.r[i] = r[i];
1351 nv_crtc->lut.g[i] = g[i];
1352 nv_crtc->lut.b[i] = b[i];
1353 }
1354
Ben Skeggse225f442012-11-21 14:40:21 +10001355 nv50_crtc_lut_load(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001356}
1357
1358static void
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001359nv50_crtc_cursor_restore(struct nouveau_crtc *nv_crtc, int x, int y)
1360{
1361 nv50_crtc_cursor_move(&nv_crtc->base, x, y);
1362
1363 nv50_crtc_cursor_show_hide(nv_crtc, true, true);
1364}
1365
1366static void
Ben Skeggse225f442012-11-21 14:40:21 +10001367nv50_crtc_destroy(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001368{
1369 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001370 struct nv50_disp *disp = nv50_disp(crtc->dev);
1371 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs0ad72862014-08-10 04:10:22 +10001372 struct nv50_fbdma *fbdma;
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001373
Ben Skeggs0ad72862014-08-10 04:10:22 +10001374 list_for_each_entry(fbdma, &disp->fbdma, head) {
1375 nvif_object_fini(&fbdma->base[nv_crtc->index]);
1376 }
1377
1378 nv50_dmac_destroy(&head->ovly.base, disp->disp);
1379 nv50_pioc_destroy(&head->oimm.base);
1380 nv50_dmac_destroy(&head->sync.base, disp->disp);
1381 nv50_pioc_destroy(&head->curs.base);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001382
1383 /*XXX: this shouldn't be necessary, but the core doesn't call
1384 * disconnect() during the cleanup paths
1385 */
1386 if (head->image)
1387 nouveau_bo_unpin(head->image);
1388 nouveau_bo_ref(NULL, &head->image);
1389
Ben Skeggs5a560252014-11-10 15:52:02 +10001390 /*XXX: ditto */
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001391 if (nv_crtc->cursor.nvbo)
1392 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
1393 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001394
Ben Skeggs438d99e2011-07-05 16:48:06 +10001395 nouveau_bo_unmap(nv_crtc->lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001396 if (nv_crtc->lut.nvbo)
1397 nouveau_bo_unpin(nv_crtc->lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001398 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001399
Ben Skeggs438d99e2011-07-05 16:48:06 +10001400 drm_crtc_cleanup(crtc);
1401 kfree(crtc);
1402}
1403
Ben Skeggse225f442012-11-21 14:40:21 +10001404static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
1405 .dpms = nv50_crtc_dpms,
1406 .prepare = nv50_crtc_prepare,
1407 .commit = nv50_crtc_commit,
1408 .mode_fixup = nv50_crtc_mode_fixup,
1409 .mode_set = nv50_crtc_mode_set,
1410 .mode_set_base = nv50_crtc_mode_set_base,
1411 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
1412 .load_lut = nv50_crtc_lut_load,
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001413 .disable = nv50_crtc_disable,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001414};
1415
Ben Skeggse225f442012-11-21 14:40:21 +10001416static const struct drm_crtc_funcs nv50_crtc_func = {
1417 .cursor_set = nv50_crtc_cursor_set,
1418 .cursor_move = nv50_crtc_cursor_move,
1419 .gamma_set = nv50_crtc_gamma_set,
Dave Airlie5addcf02012-09-10 14:20:51 +10001420 .set_config = nouveau_crtc_set_config,
Ben Skeggse225f442012-11-21 14:40:21 +10001421 .destroy = nv50_crtc_destroy,
Ben Skeggs3376ee32011-11-12 14:28:12 +10001422 .page_flip = nouveau_crtc_page_flip,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001423};
1424
1425static int
Ben Skeggs0ad72862014-08-10 04:10:22 +10001426nv50_crtc_create(struct drm_device *dev, int index)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001427{
Ben Skeggsa01ca782015-08-20 14:54:15 +10001428 struct nouveau_drm *drm = nouveau_drm(dev);
1429 struct nvif_device *device = &drm->device;
Ben Skeggse225f442012-11-21 14:40:21 +10001430 struct nv50_disp *disp = nv50_disp(dev);
1431 struct nv50_head *head;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001432 struct drm_crtc *crtc;
1433 int ret, i;
1434
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001435 head = kzalloc(sizeof(*head), GFP_KERNEL);
1436 if (!head)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001437 return -ENOMEM;
1438
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001439 head->base.index = index;
Ben Skeggse225f442012-11-21 14:40:21 +10001440 head->base.set_dither = nv50_crtc_set_dither;
1441 head->base.set_scale = nv50_crtc_set_scale;
1442 head->base.set_color_vibrance = nv50_crtc_set_color_vibrance;
Ben Skeggsf9887d02012-11-21 13:03:42 +10001443 head->base.color_vibrance = 50;
1444 head->base.vibrant_hue = 0;
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01001445 head->base.cursor.set_pos = nv50_crtc_cursor_restore;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001446 for (i = 0; i < 256; i++) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001447 head->base.lut.r[i] = i << 8;
1448 head->base.lut.g[i] = i << 8;
1449 head->base.lut.b[i] = i << 8;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001450 }
1451
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001452 crtc = &head->base.base;
Ben Skeggse225f442012-11-21 14:40:21 +10001453 drm_crtc_init(dev, crtc, &nv50_crtc_func);
1454 drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001455 drm_mode_crtc_set_gamma_size(crtc, 256);
1456
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +10001457 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01001458 0, 0x0000, NULL, NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001459 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10001460 ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001461 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001462 ret = nouveau_bo_map(head->base.lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001463 if (ret)
1464 nouveau_bo_unpin(head->base.lut.nvbo);
1465 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001466 if (ret)
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001467 nouveau_bo_ref(NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001468 }
1469
1470 if (ret)
1471 goto out;
1472
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001473 /* allocate cursor resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001474 ret = nv50_curs_create(device, disp->disp, index, &head->curs);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001475 if (ret)
1476 goto out;
1477
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001478 /* allocate page flip / sync resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001479 ret = nv50_base_create(device, disp->disp, index, disp->sync->bo.offset,
1480 &head->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001481 if (ret)
1482 goto out;
1483
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001484 head->sync.addr = EVO_FLIP_SEM0(index);
1485 head->sync.data = 0x00000000;
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001486
1487 /* allocate overlay resources */
Ben Skeggsa01ca782015-08-20 14:54:15 +10001488 ret = nv50_oimm_create(device, disp->disp, index, &head->oimm);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001489 if (ret)
1490 goto out;
1491
Ben Skeggsa01ca782015-08-20 14:54:15 +10001492 ret = nv50_ovly_create(device, disp->disp, index, disp->sync->bo.offset,
1493 &head->ovly);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001494 if (ret)
1495 goto out;
1496
Ben Skeggs438d99e2011-07-05 16:48:06 +10001497out:
1498 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10001499 nv50_crtc_destroy(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001500 return ret;
1501}
1502
1503/******************************************************************************
Ben Skeggsa91d3222014-12-22 16:30:13 +10001504 * Encoder helpers
1505 *****************************************************************************/
1506static bool
1507nv50_encoder_mode_fixup(struct drm_encoder *encoder,
1508 const struct drm_display_mode *mode,
1509 struct drm_display_mode *adjusted_mode)
1510{
1511 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1512 struct nouveau_connector *nv_connector;
1513
1514 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1515 if (nv_connector && nv_connector->native_mode) {
Ben Skeggs576f7912014-12-22 17:19:26 +10001516 nv_connector->scaling_full = false;
1517 if (nv_connector->scaling_mode == DRM_MODE_SCALE_NONE) {
1518 switch (nv_connector->type) {
1519 case DCB_CONNECTOR_LVDS:
1520 case DCB_CONNECTOR_LVDS_SPWG:
1521 case DCB_CONNECTOR_eDP:
1522 /* force use of scaler for non-edid modes */
1523 if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER)
1524 return true;
1525 nv_connector->scaling_full = true;
1526 break;
1527 default:
1528 return true;
1529 }
1530 }
1531
1532 drm_mode_copy(adjusted_mode, nv_connector->native_mode);
Ben Skeggsa91d3222014-12-22 16:30:13 +10001533 }
1534
1535 return true;
1536}
1537
1538/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001539 * DAC
1540 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001541static void
Ben Skeggse225f442012-11-21 14:40:21 +10001542nv50_dac_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001543{
1544 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001545 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001546 struct {
1547 struct nv50_disp_mthd_v1 base;
1548 struct nv50_disp_dac_pwr_v0 pwr;
1549 } args = {
1550 .base.version = 1,
1551 .base.method = NV50_DISP_MTHD_V1_DAC_PWR,
1552 .base.hasht = nv_encoder->dcb->hasht,
1553 .base.hashm = nv_encoder->dcb->hashm,
1554 .pwr.state = 1,
1555 .pwr.data = 1,
1556 .pwr.vsync = (mode != DRM_MODE_DPMS_SUSPEND &&
1557 mode != DRM_MODE_DPMS_OFF),
1558 .pwr.hsync = (mode != DRM_MODE_DPMS_STANDBY &&
1559 mode != DRM_MODE_DPMS_OFF),
1560 };
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001561
Ben Skeggsbf0eb892014-08-10 04:10:26 +10001562 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001563}
1564
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001565static void
Ben Skeggse225f442012-11-21 14:40:21 +10001566nv50_dac_commit(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001567{
1568}
1569
1570static void
Ben Skeggse225f442012-11-21 14:40:21 +10001571nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001572 struct drm_display_mode *adjusted_mode)
1573{
Ben Skeggse225f442012-11-21 14:40:21 +10001574 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001575 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1576 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001577 u32 *push;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001578
Ben Skeggse225f442012-11-21 14:40:21 +10001579 nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001580
Ben Skeggs97b19b52012-11-16 11:21:37 +10001581 push = evo_wait(mast, 8);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001582 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001583 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001584 u32 syncs = 0x00000000;
1585
1586 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1587 syncs |= 0x00000001;
1588 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1589 syncs |= 0x00000002;
1590
1591 evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
1592 evo_data(push, 1 << nv_crtc->index);
1593 evo_data(push, syncs);
1594 } else {
1595 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1596 u32 syncs = 0x00000001;
1597
1598 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1599 syncs |= 0x00000008;
1600 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1601 syncs |= 0x00000010;
1602
1603 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1604 magic |= 0x00000001;
1605
1606 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1607 evo_data(push, syncs);
1608 evo_data(push, magic);
1609 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
1610 evo_data(push, 1 << nv_crtc->index);
1611 }
1612
1613 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001614 }
1615
1616 nv_encoder->crtc = encoder->crtc;
1617}
1618
1619static void
Ben Skeggse225f442012-11-21 14:40:21 +10001620nv50_dac_disconnect(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001621{
1622 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001623 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001624 const int or = nv_encoder->or;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001625 u32 *push;
1626
1627 if (nv_encoder->crtc) {
Ben Skeggse225f442012-11-21 14:40:21 +10001628 nv50_crtc_prepare(nv_encoder->crtc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001629
Ben Skeggs97b19b52012-11-16 11:21:37 +10001630 push = evo_wait(mast, 4);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001631 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001632 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001633 evo_mthd(push, 0x0400 + (or * 0x080), 1);
1634 evo_data(push, 0x00000000);
1635 } else {
1636 evo_mthd(push, 0x0180 + (or * 0x020), 1);
1637 evo_data(push, 0x00000000);
1638 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001639 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001640 }
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001641 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001642
1643 nv_encoder->crtc = NULL;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001644}
1645
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001646static enum drm_connector_status
Ben Skeggse225f442012-11-21 14:40:21 +10001647nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001648{
Ben Skeggsc4abd312014-08-10 04:10:26 +10001649 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001650 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsc4abd312014-08-10 04:10:26 +10001651 struct {
1652 struct nv50_disp_mthd_v1 base;
1653 struct nv50_disp_dac_load_v0 load;
1654 } args = {
1655 .base.version = 1,
1656 .base.method = NV50_DISP_MTHD_V1_DAC_LOAD,
1657 .base.hasht = nv_encoder->dcb->hasht,
1658 .base.hashm = nv_encoder->dcb->hashm,
1659 };
1660 int ret;
Ben Skeggsb6819932011-07-08 11:14:50 +10001661
Ben Skeggsc4abd312014-08-10 04:10:26 +10001662 args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval;
1663 if (args.load.data == 0)
1664 args.load.data = 340;
1665
1666 ret = nvif_mthd(disp->disp, 0, &args, sizeof(args));
1667 if (ret || !args.load.load)
Ben Skeggs35b21d32012-11-08 12:08:55 +10001668 return connector_status_disconnected;
Ben Skeggsb6819932011-07-08 11:14:50 +10001669
Ben Skeggs35b21d32012-11-08 12:08:55 +10001670 return connector_status_connected;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001671}
1672
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001673static void
Ben Skeggse225f442012-11-21 14:40:21 +10001674nv50_dac_destroy(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001675{
1676 drm_encoder_cleanup(encoder);
1677 kfree(encoder);
1678}
1679
Ben Skeggse225f442012-11-21 14:40:21 +10001680static const struct drm_encoder_helper_funcs nv50_dac_hfunc = {
1681 .dpms = nv50_dac_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10001682 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggse225f442012-11-21 14:40:21 +10001683 .prepare = nv50_dac_disconnect,
1684 .commit = nv50_dac_commit,
1685 .mode_set = nv50_dac_mode_set,
1686 .disable = nv50_dac_disconnect,
1687 .get_crtc = nv50_display_crtc_get,
1688 .detect = nv50_dac_detect
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001689};
1690
Ben Skeggse225f442012-11-21 14:40:21 +10001691static const struct drm_encoder_funcs nv50_dac_func = {
1692 .destroy = nv50_dac_destroy,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001693};
1694
1695static int
Ben Skeggse225f442012-11-21 14:40:21 +10001696nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001697{
Ben Skeggs5ed50202013-02-11 20:15:03 +10001698 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10001699 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001700 struct nvkm_i2c_bus *bus;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001701 struct nouveau_encoder *nv_encoder;
1702 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001703 int type = DRM_MODE_ENCODER_DAC;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001704
1705 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1706 if (!nv_encoder)
1707 return -ENOMEM;
1708 nv_encoder->dcb = dcbe;
1709 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10001710
1711 bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
1712 if (bus)
1713 nv_encoder->i2c = &bus->i2c;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001714
1715 encoder = to_drm_encoder(nv_encoder);
1716 encoder->possible_crtcs = dcbe->heads;
1717 encoder->possible_clones = 0;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001718 drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type);
Ben Skeggse225f442012-11-21 14:40:21 +10001719 drm_encoder_helper_add(encoder, &nv50_dac_hfunc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001720
1721 drm_mode_connector_attach_encoder(connector, encoder);
1722 return 0;
1723}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001724
1725/******************************************************************************
Ben Skeggs78951d22011-11-11 18:13:13 +10001726 * Audio
1727 *****************************************************************************/
1728static void
Ben Skeggse225f442012-11-21 14:40:21 +10001729nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001730{
1731 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001732 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs78951d22011-11-11 18:13:13 +10001733 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10001734 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggsd889c522014-09-15 21:11:51 +10001735 struct __packed {
1736 struct {
1737 struct nv50_disp_mthd_v1 mthd;
1738 struct nv50_disp_sor_hda_eld_v0 eld;
1739 } base;
Ben Skeggs120b0c32014-08-10 04:10:26 +10001740 u8 data[sizeof(nv_connector->base.eld)];
1741 } args = {
Ben Skeggsd889c522014-09-15 21:11:51 +10001742 .base.mthd.version = 1,
1743 .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1744 .base.mthd.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001745 .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1746 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001747 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001748
1749 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1750 if (!drm_detect_monitor_audio(nv_connector->edid))
1751 return;
1752
Ben Skeggs78951d22011-11-11 18:13:13 +10001753 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001754 memcpy(args.data, nv_connector->base.eld, sizeof(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001755
Jani Nikula938fd8a2014-10-28 16:20:48 +02001756 nvif_mthd(disp->disp, 0, &args,
1757 sizeof(args.base) + drm_eld_size(args.data));
Ben Skeggs78951d22011-11-11 18:13:13 +10001758}
1759
1760static void
Ben Skeggscc2a9072014-09-15 21:29:05 +10001761nv50_audio_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001762{
1763 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001764 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs120b0c32014-08-10 04:10:26 +10001765 struct {
1766 struct nv50_disp_mthd_v1 base;
1767 struct nv50_disp_sor_hda_eld_v0 eld;
1768 } args = {
1769 .base.version = 1,
1770 .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD,
1771 .base.hasht = nv_encoder->dcb->hasht,
Ben Skeggscc2a9072014-09-15 21:29:05 +10001772 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1773 (0x0100 << nv_crtc->index),
Ben Skeggs120b0c32014-08-10 04:10:26 +10001774 };
Ben Skeggs78951d22011-11-11 18:13:13 +10001775
Ben Skeggs120b0c32014-08-10 04:10:26 +10001776 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001777}
1778
1779/******************************************************************************
1780 * HDMI
1781 *****************************************************************************/
1782static void
Ben Skeggse225f442012-11-21 14:40:21 +10001783nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001784{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001785 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1786 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001787 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001788 struct {
1789 struct nv50_disp_mthd_v1 base;
1790 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1791 } args = {
1792 .base.version = 1,
1793 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1794 .base.hasht = nv_encoder->dcb->hasht,
1795 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1796 (0x0100 << nv_crtc->index),
1797 .pwr.state = 1,
1798 .pwr.rekey = 56, /* binary driver, and tegra, constant */
1799 };
1800 struct nouveau_connector *nv_connector;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001801 u32 max_ac_packet;
1802
1803 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1804 if (!drm_detect_hdmi_monitor(nv_connector->edid))
1805 return;
1806
1807 max_ac_packet = mode->htotal - mode->hdisplay;
Ben Skeggse00f2232014-08-10 04:10:26 +10001808 max_ac_packet -= args.pwr.rekey;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001809 max_ac_packet -= 18; /* constant from tegra */
Ben Skeggse00f2232014-08-10 04:10:26 +10001810 args.pwr.max_ac_packet = max_ac_packet / 32;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001811
Ben Skeggse00f2232014-08-10 04:10:26 +10001812 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggse225f442012-11-21 14:40:21 +10001813 nv50_audio_mode_set(encoder, mode);
Ben Skeggs78951d22011-11-11 18:13:13 +10001814}
1815
1816static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001817nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001818{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001819 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001820 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggse00f2232014-08-10 04:10:26 +10001821 struct {
1822 struct nv50_disp_mthd_v1 base;
1823 struct nv50_disp_sor_hdmi_pwr_v0 pwr;
1824 } args = {
1825 .base.version = 1,
1826 .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR,
1827 .base.hasht = nv_encoder->dcb->hasht,
1828 .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) |
1829 (0x0100 << nv_crtc->index),
1830 };
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001831
Ben Skeggse00f2232014-08-10 04:10:26 +10001832 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs78951d22011-11-11 18:13:13 +10001833}
1834
1835/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001836 * SOR
1837 *****************************************************************************/
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001838static void
Ben Skeggse225f442012-11-21 14:40:21 +10001839nv50_sor_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001840{
1841 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001842 struct nv50_disp *disp = nv50_disp(encoder->dev);
1843 struct {
1844 struct nv50_disp_mthd_v1 base;
1845 struct nv50_disp_sor_pwr_v0 pwr;
1846 } args = {
1847 .base.version = 1,
1848 .base.method = NV50_DISP_MTHD_V1_SOR_PWR,
1849 .base.hasht = nv_encoder->dcb->hasht,
1850 .base.hashm = nv_encoder->dcb->hashm,
1851 .pwr.state = mode == DRM_MODE_DPMS_ON,
1852 };
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001853 struct {
1854 struct nv50_disp_mthd_v1 base;
1855 struct nv50_disp_sor_dp_pwr_v0 pwr;
1856 } link = {
1857 .base.version = 1,
1858 .base.method = NV50_DISP_MTHD_V1_SOR_DP_PWR,
1859 .base.hasht = nv_encoder->dcb->hasht,
1860 .base.hashm = nv_encoder->dcb->hashm,
1861 .pwr.state = mode == DRM_MODE_DPMS_ON,
1862 };
Ben Skeggs83fc0832011-07-05 13:08:40 +10001863 struct drm_device *dev = encoder->dev;
1864 struct drm_encoder *partner;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001865
1866 nv_encoder->last_dpms = mode;
1867
1868 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
1869 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
1870
1871 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
1872 continue;
1873
1874 if (nv_partner != nv_encoder &&
Ben Skeggs26cfa812011-11-17 09:10:02 +10001875 nv_partner->dcb->or == nv_encoder->dcb->or) {
Ben Skeggs83fc0832011-07-05 13:08:40 +10001876 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
1877 return;
1878 break;
1879 }
1880 }
1881
Ben Skeggs48743222014-05-31 01:48:06 +10001882 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001883 args.pwr.state = 1;
1884 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggsc02ed2b2014-08-10 04:10:27 +10001885 nvif_mthd(disp->disp, 0, &link, sizeof(link));
Ben Skeggs48743222014-05-31 01:48:06 +10001886 } else {
Ben Skeggsd55b4af2014-08-10 04:10:26 +10001887 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggs48743222014-05-31 01:48:06 +10001888 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001889}
1890
Ben Skeggs83fc0832011-07-05 13:08:40 +10001891static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001892nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
1893{
1894 struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
1895 u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
1896 if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10001897 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10001898 evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
1899 evo_data(push, (nv_encoder->ctrl = temp));
1900 } else {
1901 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
1902 evo_data(push, (nv_encoder->ctrl = temp));
1903 }
1904 evo_kick(push, mast);
1905 }
1906}
1907
1908static void
Ben Skeggse225f442012-11-21 14:40:21 +10001909nv50_sor_disconnect(struct drm_encoder *encoder)
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001910{
1911 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001912 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001913
1914 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1915 nv_encoder->crtc = NULL;
Ben Skeggse84a35a2014-06-05 10:59:55 +10001916
1917 if (nv_crtc) {
1918 nv50_crtc_prepare(&nv_crtc->base);
1919 nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
Ben Skeggscc2a9072014-09-15 21:29:05 +10001920 nv50_audio_disconnect(encoder, nv_crtc);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001921 nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc);
1922 }
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001923}
1924
1925static void
Ben Skeggse225f442012-11-21 14:40:21 +10001926nv50_sor_commit(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001927{
1928}
1929
1930static void
Ben Skeggse225f442012-11-21 14:40:21 +10001931nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001932 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001933{
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001934 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1935 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1936 struct {
1937 struct nv50_disp_mthd_v1 base;
1938 struct nv50_disp_sor_lvds_script_v0 lvds;
1939 } lvds = {
1940 .base.version = 1,
1941 .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT,
1942 .base.hasht = nv_encoder->dcb->hasht,
1943 .base.hashm = nv_encoder->dcb->hashm,
1944 };
Ben Skeggse225f442012-11-21 14:40:21 +10001945 struct nv50_disp *disp = nv50_disp(encoder->dev);
1946 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001947 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +10001948 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001949 struct nouveau_connector *nv_connector;
Ben Skeggs77145f12012-07-31 16:16:21 +10001950 struct nvbios *bios = &drm->vbios;
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001951 u32 mask, ctrl;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001952 u8 owner = 1 << nv_crtc->index;
1953 u8 proto = 0xf;
1954 u8 depth = 0x0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001955
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001956 nv_connector = nouveau_encoder_connector_get(nv_encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001957 nv_encoder->crtc = encoder->crtc;
1958
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001959 switch (nv_encoder->dcb->type) {
Ben Skeggscb75d972012-07-11 10:44:20 +10001960 case DCB_OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001961 if (nv_encoder->dcb->sorconf.link & 1) {
1962 if (mode->clock < 165000)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001963 proto = 0x1;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001964 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001965 proto = 0x5;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001966 } else {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001967 proto = 0x2;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001968 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001969
Ben Skeggse84a35a2014-06-05 10:59:55 +10001970 nv50_hdmi_mode_set(&nv_encoder->base.base, mode);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001971 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001972 case DCB_OUTPUT_LVDS:
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001973 proto = 0x0;
1974
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001975 if (bios->fp_no_ddc) {
1976 if (bios->fp.dual_link)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001977 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001978 if (bios->fp.if_is_24bit)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001979 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001980 } else {
Ben Skeggsbefb51e2011-11-18 10:23:59 +10001981 if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001982 if (((u8 *)nv_connector->edid)[121] == 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001983 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001984 } else
1985 if (mode->clock >= bios->fp.duallink_transition_clk) {
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001986 lvds.lvds.script |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001987 }
1988
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001989 if (lvds.lvds.script & 0x0100) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001990 if (bios->fp.strapless_is_24bit & 2)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001991 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001992 } else {
1993 if (bios->fp.strapless_is_24bit & 1)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001994 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001995 }
1996
1997 if (nv_connector->base.display_info.bpc == 8)
Ben Skeggsa3761fa2014-08-10 04:10:27 +10001998 lvds.lvds.script |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001999 }
Ben Skeggs4a230fa2012-11-09 11:25:37 +10002000
Ben Skeggsa3761fa2014-08-10 04:10:27 +10002001 nvif_mthd(disp->disp, 0, &lvds, sizeof(lvds));
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002002 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10002003 case DCB_OUTPUT_DP:
Ben Skeggs3488c572012-03-12 11:42:20 +10002004 if (nv_connector->base.display_info.bpc == 6) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002005 nv_encoder->dp.datarate = mode->clock * 18 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002006 depth = 0x2;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10002007 } else
2008 if (nv_connector->base.display_info.bpc == 8) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002009 nv_encoder->dp.datarate = mode->clock * 24 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002010 depth = 0x5;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10002011 } else {
2012 nv_encoder->dp.datarate = mode->clock * 30 / 8;
2013 depth = 0x6;
Ben Skeggs3488c572012-03-12 11:42:20 +10002014 }
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002015
2016 if (nv_encoder->dcb->sorconf.link & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002017 proto = 0x8;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002018 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002019 proto = 0x9;
Ben Skeggs3eee8642014-09-15 15:20:47 +10002020 nv50_audio_mode_set(encoder, mode);
Ben Skeggs6e83fda2012-03-11 01:28:48 +10002021 break;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10002022 default:
2023 BUG_ON(1);
2024 break;
2025 }
Ben Skeggsff8ff502011-07-08 11:53:37 +10002026
Ben Skeggse84a35a2014-06-05 10:59:55 +10002027 nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002028
Ben Skeggs648d4df2014-08-10 04:10:27 +10002029 if (nv50_vers(mast) >= GF110_DISP) {
Ben Skeggse84a35a2014-06-05 10:59:55 +10002030 u32 *push = evo_wait(mast, 3);
2031 if (push) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002032 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
2033 u32 syncs = 0x00000001;
2034
2035 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2036 syncs |= 0x00000008;
2037 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2038 syncs |= 0x00000010;
2039
2040 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
2041 magic |= 0x00000001;
2042
2043 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
2044 evo_data(push, syncs | (depth << 6));
2045 evo_data(push, magic);
Ben Skeggse84a35a2014-06-05 10:59:55 +10002046 evo_kick(push, mast);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10002047 }
2048
Ben Skeggse84a35a2014-06-05 10:59:55 +10002049 ctrl = proto << 8;
2050 mask = 0x00000f00;
2051 } else {
2052 ctrl = (depth << 16) | (proto << 8);
2053 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2054 ctrl |= 0x00001000;
2055 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2056 ctrl |= 0x00002000;
2057 mask = 0x000f3f00;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002058 }
2059
Ben Skeggse84a35a2014-06-05 10:59:55 +10002060 nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002061}
2062
2063static void
Ben Skeggse225f442012-11-21 14:40:21 +10002064nv50_sor_destroy(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002065{
2066 drm_encoder_cleanup(encoder);
2067 kfree(encoder);
2068}
2069
Ben Skeggse225f442012-11-21 14:40:21 +10002070static const struct drm_encoder_helper_funcs nv50_sor_hfunc = {
2071 .dpms = nv50_sor_dpms,
Ben Skeggsa91d3222014-12-22 16:30:13 +10002072 .mode_fixup = nv50_encoder_mode_fixup,
Ben Skeggs5a885f02013-02-20 14:34:18 +10002073 .prepare = nv50_sor_disconnect,
Ben Skeggse225f442012-11-21 14:40:21 +10002074 .commit = nv50_sor_commit,
2075 .mode_set = nv50_sor_mode_set,
2076 .disable = nv50_sor_disconnect,
2077 .get_crtc = nv50_display_crtc_get,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002078};
2079
Ben Skeggse225f442012-11-21 14:40:21 +10002080static const struct drm_encoder_funcs nv50_sor_func = {
2081 .destroy = nv50_sor_destroy,
Ben Skeggs83fc0832011-07-05 13:08:40 +10002082};
2083
2084static int
Ben Skeggse225f442012-11-21 14:40:21 +10002085nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs83fc0832011-07-05 13:08:40 +10002086{
Ben Skeggs5ed50202013-02-11 20:15:03 +10002087 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002088 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002089 struct nouveau_encoder *nv_encoder;
2090 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10002091 int type;
2092
2093 switch (dcbe->type) {
2094 case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
2095 case DCB_OUTPUT_TMDS:
2096 case DCB_OUTPUT_DP:
2097 default:
2098 type = DRM_MODE_ENCODER_TMDS;
2099 break;
2100 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10002101
2102 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2103 if (!nv_encoder)
2104 return -ENOMEM;
2105 nv_encoder->dcb = dcbe;
2106 nv_encoder->or = ffs(dcbe->or) - 1;
2107 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
2108
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002109 if (dcbe->type == DCB_OUTPUT_DP) {
2110 struct nvkm_i2c_aux *aux =
2111 nvkm_i2c_aux_find(i2c, dcbe->i2c_index);
2112 if (aux) {
2113 nv_encoder->i2c = &aux->i2c;
2114 nv_encoder->aux = aux;
2115 }
2116 } else {
2117 struct nvkm_i2c_bus *bus =
2118 nvkm_i2c_bus_find(i2c, dcbe->i2c_index);
2119 if (bus)
2120 nv_encoder->i2c = &bus->i2c;
2121 }
2122
Ben Skeggs83fc0832011-07-05 13:08:40 +10002123 encoder = to_drm_encoder(nv_encoder);
2124 encoder->possible_crtcs = dcbe->heads;
2125 encoder->possible_clones = 0;
Ben Skeggs5ed50202013-02-11 20:15:03 +10002126 drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type);
Ben Skeggse225f442012-11-21 14:40:21 +10002127 drm_encoder_helper_add(encoder, &nv50_sor_hfunc);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002128
2129 drm_mode_connector_attach_encoder(connector, encoder);
2130 return 0;
2131}
Ben Skeggs26f6d882011-07-04 16:25:18 +10002132
2133/******************************************************************************
Ben Skeggseb6313a2013-02-11 09:52:58 +10002134 * PIOR
2135 *****************************************************************************/
2136
2137static void
2138nv50_pior_dpms(struct drm_encoder *encoder, int mode)
2139{
2140 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2141 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs67cb49c2014-08-10 04:10:27 +10002142 struct {
2143 struct nv50_disp_mthd_v1 base;
2144 struct nv50_disp_pior_pwr_v0 pwr;
2145 } args = {
2146 .base.version = 1,
2147 .base.method = NV50_DISP_MTHD_V1_PIOR_PWR,
2148 .base.hasht = nv_encoder->dcb->hasht,
2149 .base.hashm = nv_encoder->dcb->hashm,
2150 .pwr.state = mode == DRM_MODE_DPMS_ON,
2151 .pwr.type = nv_encoder->dcb->type,
2152 };
2153
2154 nvif_mthd(disp->disp, 0, &args, sizeof(args));
Ben Skeggseb6313a2013-02-11 09:52:58 +10002155}
2156
2157static bool
2158nv50_pior_mode_fixup(struct drm_encoder *encoder,
2159 const struct drm_display_mode *mode,
2160 struct drm_display_mode *adjusted_mode)
2161{
Ben Skeggsa91d3222014-12-22 16:30:13 +10002162 if (!nv50_encoder_mode_fixup(encoder, mode, adjusted_mode))
2163 return false;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002164 adjusted_mode->clock *= 2;
2165 return true;
2166}
2167
2168static void
2169nv50_pior_commit(struct drm_encoder *encoder)
2170{
2171}
2172
2173static void
2174nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
2175 struct drm_display_mode *adjusted_mode)
2176{
2177 struct nv50_mast *mast = nv50_mast(encoder->dev);
2178 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2179 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
2180 struct nouveau_connector *nv_connector;
2181 u8 owner = 1 << nv_crtc->index;
2182 u8 proto, depth;
2183 u32 *push;
2184
2185 nv_connector = nouveau_encoder_connector_get(nv_encoder);
2186 switch (nv_connector->base.display_info.bpc) {
2187 case 10: depth = 0x6; break;
2188 case 8: depth = 0x5; break;
2189 case 6: depth = 0x2; break;
2190 default: depth = 0x0; break;
2191 }
2192
2193 switch (nv_encoder->dcb->type) {
2194 case DCB_OUTPUT_TMDS:
2195 case DCB_OUTPUT_DP:
2196 proto = 0x0;
2197 break;
2198 default:
2199 BUG_ON(1);
2200 break;
2201 }
2202
2203 nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
2204
2205 push = evo_wait(mast, 8);
2206 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002207 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002208 u32 ctrl = (depth << 16) | (proto << 8) | owner;
2209 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
2210 ctrl |= 0x00001000;
2211 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
2212 ctrl |= 0x00002000;
2213 evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
2214 evo_data(push, ctrl);
2215 }
2216
2217 evo_kick(push, mast);
2218 }
2219
2220 nv_encoder->crtc = encoder->crtc;
2221}
2222
2223static void
2224nv50_pior_disconnect(struct drm_encoder *encoder)
2225{
2226 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
2227 struct nv50_mast *mast = nv50_mast(encoder->dev);
2228 const int or = nv_encoder->or;
2229 u32 *push;
2230
2231 if (nv_encoder->crtc) {
2232 nv50_crtc_prepare(nv_encoder->crtc);
2233
2234 push = evo_wait(mast, 4);
2235 if (push) {
Ben Skeggs648d4df2014-08-10 04:10:27 +10002236 if (nv50_vers(mast) < GF110_DISP_CORE_CHANNEL_DMA) {
Ben Skeggseb6313a2013-02-11 09:52:58 +10002237 evo_mthd(push, 0x0700 + (or * 0x040), 1);
2238 evo_data(push, 0x00000000);
2239 }
Ben Skeggseb6313a2013-02-11 09:52:58 +10002240 evo_kick(push, mast);
2241 }
2242 }
2243
2244 nv_encoder->crtc = NULL;
2245}
2246
2247static void
2248nv50_pior_destroy(struct drm_encoder *encoder)
2249{
2250 drm_encoder_cleanup(encoder);
2251 kfree(encoder);
2252}
2253
2254static const struct drm_encoder_helper_funcs nv50_pior_hfunc = {
2255 .dpms = nv50_pior_dpms,
2256 .mode_fixup = nv50_pior_mode_fixup,
2257 .prepare = nv50_pior_disconnect,
2258 .commit = nv50_pior_commit,
2259 .mode_set = nv50_pior_mode_set,
2260 .disable = nv50_pior_disconnect,
2261 .get_crtc = nv50_display_crtc_get,
2262};
2263
2264static const struct drm_encoder_funcs nv50_pior_func = {
2265 .destroy = nv50_pior_destroy,
2266};
2267
2268static int
2269nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
2270{
2271 struct nouveau_drm *drm = nouveau_drm(connector->dev);
Ben Skeggsbe83cd42015-01-14 15:36:34 +10002272 struct nvkm_i2c *i2c = nvxx_i2c(&drm->device);
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002273 struct nvkm_i2c_bus *bus = NULL;
2274 struct nvkm_i2c_aux *aux = NULL;
2275 struct i2c_adapter *ddc;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002276 struct nouveau_encoder *nv_encoder;
2277 struct drm_encoder *encoder;
2278 int type;
2279
2280 switch (dcbe->type) {
2281 case DCB_OUTPUT_TMDS:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002282 bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev));
2283 ddc = bus ? &bus->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002284 type = DRM_MODE_ENCODER_TMDS;
2285 break;
2286 case DCB_OUTPUT_DP:
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002287 aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev));
2288 ddc = aux ? &aux->i2c : NULL;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002289 type = DRM_MODE_ENCODER_TMDS;
2290 break;
2291 default:
2292 return -ENODEV;
2293 }
2294
2295 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2296 if (!nv_encoder)
2297 return -ENOMEM;
2298 nv_encoder->dcb = dcbe;
2299 nv_encoder->or = ffs(dcbe->or) - 1;
2300 nv_encoder->i2c = ddc;
Ben Skeggs2aa5eac2015-08-20 14:54:15 +10002301 nv_encoder->aux = aux;
Ben Skeggseb6313a2013-02-11 09:52:58 +10002302
2303 encoder = to_drm_encoder(nv_encoder);
2304 encoder->possible_crtcs = dcbe->heads;
2305 encoder->possible_clones = 0;
2306 drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type);
2307 drm_encoder_helper_add(encoder, &nv50_pior_hfunc);
2308
2309 drm_mode_connector_attach_encoder(connector, encoder);
2310 return 0;
2311}
2312
2313/******************************************************************************
Ben Skeggsab0af552014-08-10 04:10:19 +10002314 * Framebuffer
2315 *****************************************************************************/
2316
Ben Skeggs8a423642014-08-10 04:10:19 +10002317static void
Ben Skeggs0ad72862014-08-10 04:10:22 +10002318nv50_fbdma_fini(struct nv50_fbdma *fbdma)
Ben Skeggs8a423642014-08-10 04:10:19 +10002319{
Ben Skeggs0ad72862014-08-10 04:10:22 +10002320 int i;
2321 for (i = 0; i < ARRAY_SIZE(fbdma->base); i++)
2322 nvif_object_fini(&fbdma->base[i]);
2323 nvif_object_fini(&fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002324 list_del(&fbdma->head);
2325 kfree(fbdma);
2326}
2327
2328static int
2329nv50_fbdma_init(struct drm_device *dev, u32 name, u64 offset, u64 length, u8 kind)
2330{
2331 struct nouveau_drm *drm = nouveau_drm(dev);
2332 struct nv50_disp *disp = nv50_disp(dev);
2333 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggs4acfd702014-08-10 04:10:24 +10002334 struct __attribute__ ((packed)) {
2335 struct nv_dma_v0 base;
2336 union {
2337 struct nv50_dma_v0 nv50;
2338 struct gf100_dma_v0 gf100;
2339 struct gf110_dma_v0 gf110;
2340 };
2341 } args = {};
Ben Skeggs8a423642014-08-10 04:10:19 +10002342 struct nv50_fbdma *fbdma;
2343 struct drm_crtc *crtc;
Ben Skeggs4acfd702014-08-10 04:10:24 +10002344 u32 size = sizeof(args.base);
Ben Skeggs8a423642014-08-10 04:10:19 +10002345 int ret;
2346
2347 list_for_each_entry(fbdma, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002348 if (fbdma->core.handle == name)
Ben Skeggs8a423642014-08-10 04:10:19 +10002349 return 0;
2350 }
2351
2352 fbdma = kzalloc(sizeof(*fbdma), GFP_KERNEL);
2353 if (!fbdma)
2354 return -ENOMEM;
2355 list_add(&fbdma->head, &disp->fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002356
Ben Skeggs4acfd702014-08-10 04:10:24 +10002357 args.base.target = NV_DMA_V0_TARGET_VRAM;
2358 args.base.access = NV_DMA_V0_ACCESS_RDWR;
2359 args.base.start = offset;
2360 args.base.limit = offset + length - 1;
Ben Skeggs8a423642014-08-10 04:10:19 +10002361
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002362 if (drm->device.info.chipset < 0x80) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002363 args.nv50.part = NV50_DMA_V0_PART_256;
2364 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002365 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002366 if (drm->device.info.chipset < 0xc0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002367 args.nv50.part = NV50_DMA_V0_PART_256;
2368 args.nv50.kind = kind;
2369 size += sizeof(args.nv50);
Ben Skeggs8a423642014-08-10 04:10:19 +10002370 } else
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002371 if (drm->device.info.chipset < 0xd0) {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002372 args.gf100.kind = kind;
2373 size += sizeof(args.gf100);
Ben Skeggs8a423642014-08-10 04:10:19 +10002374 } else {
Ben Skeggs4acfd702014-08-10 04:10:24 +10002375 args.gf110.page = GF110_DMA_V0_PAGE_LP;
2376 args.gf110.kind = kind;
2377 size += sizeof(args.gf110);
Ben Skeggs8a423642014-08-10 04:10:19 +10002378 }
2379
2380 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002381 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsa01ca782015-08-20 14:54:15 +10002382 int ret = nvif_object_init(&head->sync.base.base.user, name,
2383 NV_DMA_IN_MEMORY, &args, size,
Ben Skeggs0ad72862014-08-10 04:10:22 +10002384 &fbdma->base[head->base.index]);
Ben Skeggs8a423642014-08-10 04:10:19 +10002385 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002386 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002387 return ret;
2388 }
2389 }
2390
Ben Skeggsa01ca782015-08-20 14:54:15 +10002391 ret = nvif_object_init(&mast->base.base.user, name, NV_DMA_IN_MEMORY,
2392 &args, size, &fbdma->core);
Ben Skeggs8a423642014-08-10 04:10:19 +10002393 if (ret) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002394 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002395 return ret;
2396 }
2397
2398 return 0;
2399}
2400
Ben Skeggsab0af552014-08-10 04:10:19 +10002401static void
2402nv50_fb_dtor(struct drm_framebuffer *fb)
2403{
2404}
2405
2406static int
2407nv50_fb_ctor(struct drm_framebuffer *fb)
2408{
2409 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
2410 struct nouveau_drm *drm = nouveau_drm(fb->dev);
2411 struct nouveau_bo *nvbo = nv_fb->nvbo;
Ben Skeggs8a423642014-08-10 04:10:19 +10002412 struct nv50_disp *disp = nv50_disp(fb->dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002413 u8 kind = nouveau_bo_tile_layout(nvbo) >> 8;
2414 u8 tile = nvbo->tile_mode;
Ben Skeggsab0af552014-08-10 04:10:19 +10002415
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002416 if (drm->device.info.chipset >= 0xc0)
Ben Skeggs8a423642014-08-10 04:10:19 +10002417 tile >>= 4; /* yep.. */
2418
Ben Skeggsab0af552014-08-10 04:10:19 +10002419 switch (fb->depth) {
2420 case 8: nv_fb->r_format = 0x1e00; break;
2421 case 15: nv_fb->r_format = 0xe900; break;
2422 case 16: nv_fb->r_format = 0xe800; break;
2423 case 24:
2424 case 32: nv_fb->r_format = 0xcf00; break;
2425 case 30: nv_fb->r_format = 0xd100; break;
2426 default:
2427 NV_ERROR(drm, "unknown depth %d\n", fb->depth);
2428 return -EINVAL;
2429 }
2430
Ben Skeggs648d4df2014-08-10 04:10:27 +10002431 if (disp->disp->oclass < G82_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002432 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2433 (fb->pitches[0] | 0x00100000);
2434 nv_fb->r_format |= kind << 16;
2435 } else
Ben Skeggs648d4df2014-08-10 04:10:27 +10002436 if (disp->disp->oclass < GF110_DISP) {
Ben Skeggs8a423642014-08-10 04:10:19 +10002437 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2438 (fb->pitches[0] | 0x00100000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002439 } else {
Ben Skeggs8a423642014-08-10 04:10:19 +10002440 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2441 (fb->pitches[0] | 0x01000000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002442 }
Ben Skeggs8a423642014-08-10 04:10:19 +10002443 nv_fb->r_handle = 0xffff0000 | kind;
Ben Skeggsab0af552014-08-10 04:10:19 +10002444
Ben Skeggsf392ec42014-08-10 04:10:28 +10002445 return nv50_fbdma_init(fb->dev, nv_fb->r_handle, 0,
2446 drm->device.info.ram_user, kind);
Ben Skeggsab0af552014-08-10 04:10:19 +10002447}
2448
2449/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10002450 * Init
2451 *****************************************************************************/
Ben Skeggsab0af552014-08-10 04:10:19 +10002452
Ben Skeggs2a44e492011-11-09 11:36:33 +10002453void
Ben Skeggse225f442012-11-21 14:40:21 +10002454nv50_display_fini(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002455{
Ben Skeggs26f6d882011-07-04 16:25:18 +10002456}
2457
2458int
Ben Skeggse225f442012-11-21 14:40:21 +10002459nv50_display_init(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002460{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002461 struct nv50_disp *disp = nv50_disp(dev);
2462 struct drm_crtc *crtc;
2463 u32 *push;
2464
2465 push = evo_wait(nv50_mast(dev), 32);
2466 if (!push)
2467 return -EBUSY;
2468
2469 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2470 struct nv50_sync *sync = nv50_sync(crtc);
Maarten Lankhorst4dc63932015-01-13 09:18:49 +01002471
2472 nv50_crtc_lut_load(crtc);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002473 nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002474 }
2475
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002476 evo_mthd(push, 0x0088, 1);
Ben Skeggsf45f55c2014-08-10 04:10:23 +10002477 evo_data(push, nv50_mast(dev)->base.sync.handle);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002478 evo_kick(push, nv50_mast(dev));
2479 return 0;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002480}
2481
2482void
Ben Skeggse225f442012-11-21 14:40:21 +10002483nv50_display_destroy(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002484{
Ben Skeggse225f442012-11-21 14:40:21 +10002485 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002486 struct nv50_fbdma *fbdma, *fbtmp;
2487
2488 list_for_each_entry_safe(fbdma, fbtmp, &disp->fbdma, head) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002489 nv50_fbdma_fini(fbdma);
Ben Skeggs8a423642014-08-10 04:10:19 +10002490 }
Ben Skeggs26f6d882011-07-04 16:25:18 +10002491
Ben Skeggs0ad72862014-08-10 04:10:22 +10002492 nv50_dmac_destroy(&disp->mast.base, disp->disp);
Ben Skeggsbdb8c212011-11-12 01:30:24 +10002493
Ben Skeggs816af2f2011-11-16 15:48:48 +10002494 nouveau_bo_unmap(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002495 if (disp->sync)
2496 nouveau_bo_unpin(disp->sync);
Ben Skeggs816af2f2011-11-16 15:48:48 +10002497 nouveau_bo_ref(NULL, &disp->sync);
Ben Skeggs51beb422011-07-05 10:33:08 +10002498
Ben Skeggs77145f12012-07-31 16:16:21 +10002499 nouveau_display(dev)->priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002500 kfree(disp);
2501}
2502
2503int
Ben Skeggse225f442012-11-21 14:40:21 +10002504nv50_display_create(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002505{
Ben Skeggs967e7bd2014-08-10 04:10:22 +10002506 struct nvif_device *device = &nouveau_drm(dev)->device;
Ben Skeggs77145f12012-07-31 16:16:21 +10002507 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs77145f12012-07-31 16:16:21 +10002508 struct dcb_table *dcb = &drm->vbios.dcb;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002509 struct drm_connector *connector, *tmp;
Ben Skeggse225f442012-11-21 14:40:21 +10002510 struct nv50_disp *disp;
Ben Skeggscb75d972012-07-11 10:44:20 +10002511 struct dcb_output *dcbe;
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002512 int crtcs, ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002513
2514 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
2515 if (!disp)
2516 return -ENOMEM;
Ben Skeggs8a423642014-08-10 04:10:19 +10002517 INIT_LIST_HEAD(&disp->fbdma);
Ben Skeggs77145f12012-07-31 16:16:21 +10002518
2519 nouveau_display(dev)->priv = disp;
Ben Skeggse225f442012-11-21 14:40:21 +10002520 nouveau_display(dev)->dtor = nv50_display_destroy;
2521 nouveau_display(dev)->init = nv50_display_init;
2522 nouveau_display(dev)->fini = nv50_display_fini;
Ben Skeggsab0af552014-08-10 04:10:19 +10002523 nouveau_display(dev)->fb_ctor = nv50_fb_ctor;
2524 nouveau_display(dev)->fb_dtor = nv50_fb_dtor;
Ben Skeggs0ad72862014-08-10 04:10:22 +10002525 disp->disp = &nouveau_display(dev)->disp;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002526
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002527 /* small shared memory area we use for notifiers and semaphores */
2528 ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
Maarten Lankhorstbb6178b2014-01-09 11:03:15 +01002529 0, 0x0000, NULL, NULL, &disp->sync);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002530 if (!ret) {
Ben Skeggs547ad072014-11-10 12:35:06 +10002531 ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002532 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002533 ret = nouveau_bo_map(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002534 if (ret)
2535 nouveau_bo_unpin(disp->sync);
2536 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002537 if (ret)
2538 nouveau_bo_ref(NULL, &disp->sync);
2539 }
2540
2541 if (ret)
2542 goto out;
2543
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002544 /* allocate master evo channel */
Ben Skeggsa01ca782015-08-20 14:54:15 +10002545 ret = nv50_core_create(device, disp->disp, disp->sync->bo.offset,
Ben Skeggs410f3ec2014-08-10 04:10:25 +10002546 &disp->mast);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002547 if (ret)
2548 goto out;
2549
Ben Skeggs438d99e2011-07-05 16:48:06 +10002550 /* create crtc objects to represent the hw heads */
Ben Skeggs648d4df2014-08-10 04:10:27 +10002551 if (disp->disp->oclass >= GF110_DISP)
Ben Skeggsa01ca782015-08-20 14:54:15 +10002552 crtcs = nvif_rd32(&device->object, 0x022448);
Ben Skeggs63718a02012-11-16 11:44:14 +10002553 else
2554 crtcs = 2;
2555
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002556 for (i = 0; i < crtcs; i++) {
Ben Skeggs0ad72862014-08-10 04:10:22 +10002557 ret = nv50_crtc_create(dev, i);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002558 if (ret)
2559 goto out;
2560 }
2561
Ben Skeggs83fc0832011-07-05 13:08:40 +10002562 /* create encoder/connector objects based on VBIOS DCB table */
2563 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
2564 connector = nouveau_connector_create(dev, dcbe->connector);
2565 if (IS_ERR(connector))
2566 continue;
2567
Ben Skeggseb6313a2013-02-11 09:52:58 +10002568 if (dcbe->location == DCB_LOC_ON_CHIP) {
2569 switch (dcbe->type) {
2570 case DCB_OUTPUT_TMDS:
2571 case DCB_OUTPUT_LVDS:
2572 case DCB_OUTPUT_DP:
2573 ret = nv50_sor_create(connector, dcbe);
2574 break;
2575 case DCB_OUTPUT_ANALOG:
2576 ret = nv50_dac_create(connector, dcbe);
2577 break;
2578 default:
2579 ret = -ENODEV;
2580 break;
2581 }
2582 } else {
2583 ret = nv50_pior_create(connector, dcbe);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002584 }
2585
Ben Skeggseb6313a2013-02-11 09:52:58 +10002586 if (ret) {
2587 NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
2588 dcbe->location, dcbe->type,
2589 ffs(dcbe->or) - 1, ret);
Ben Skeggs94f54f52013-03-05 22:26:06 +10002590 ret = 0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002591 }
2592 }
2593
2594 /* cull any connectors we created that don't have an encoder */
2595 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
2596 if (connector->encoder_ids[0])
2597 continue;
2598
Ben Skeggs77145f12012-07-31 16:16:21 +10002599 NV_WARN(drm, "%s has no encoders, removing\n",
Jani Nikula8c6c3612014-06-03 14:56:18 +03002600 connector->name);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002601 connector->funcs->destroy(connector);
2602 }
2603
Ben Skeggs26f6d882011-07-04 16:25:18 +10002604out:
2605 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10002606 nv50_display_destroy(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002607 return ret;
2608}