blob: 61fc682accddfae45dad5521c6f30bb1cc39c9be [file] [log] [blame]
Ben Skeggs56d237d2014-05-19 14:54:33 +10001/*
Ben Skeggs26f6d882011-07-04 16:25:18 +10002 * Copyright 2011 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
Ben Skeggs51beb422011-07-05 10:33:08 +100025#include <linux/dma-mapping.h>
Ben Skeggs83fc0832011-07-05 13:08:40 +100026
David Howells760285e2012-10-02 18:01:07 +010027#include <drm/drmP.h>
28#include <drm/drm_crtc_helper.h>
Ben Skeggs48743222014-05-31 01:48:06 +100029#include <drm/drm_dp_helper.h>
Ben Skeggs26f6d882011-07-04 16:25:18 +100030
Ben Skeggs77145f12012-07-31 16:16:21 +100031#include "nouveau_drm.h"
32#include "nouveau_dma.h"
33#include "nouveau_gem.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100034#include "nouveau_connector.h"
35#include "nouveau_encoder.h"
36#include "nouveau_crtc.h"
Ben Skeggsf589be82012-07-22 11:55:54 +100037#include "nouveau_fence.h"
Ben Skeggs3a89cd02011-07-07 10:47:10 +100038#include "nv50_display.h"
Ben Skeggs26f6d882011-07-04 16:25:18 +100039
Ben Skeggsb5a794b2012-10-16 14:18:32 +100040#include <core/client.h>
Ben Skeggs77145f12012-07-31 16:16:21 +100041#include <core/gpuobj.h>
Ben Skeggsb5a794b2012-10-16 14:18:32 +100042#include <core/class.h>
Ben Skeggs77145f12012-07-31 16:16:21 +100043
44#include <subdev/timer.h>
45#include <subdev/bar.h>
46#include <subdev/fb.h>
Ben Skeggs5ed50202013-02-11 20:15:03 +100047#include <subdev/i2c.h>
Ben Skeggs77145f12012-07-31 16:16:21 +100048
Ben Skeggs8a464382011-11-12 23:52:07 +100049#define EVO_DMA_NR 9
50
Ben Skeggsbdb8c212011-11-12 01:30:24 +100051#define EVO_MASTER (0x00)
Ben Skeggsa63a97e2011-11-16 15:22:34 +100052#define EVO_FLIP(c) (0x01 + (c))
Ben Skeggs8a464382011-11-12 23:52:07 +100053#define EVO_OVLY(c) (0x05 + (c))
54#define EVO_OIMM(c) (0x09 + (c))
Ben Skeggsbdb8c212011-11-12 01:30:24 +100055#define EVO_CURS(c) (0x0d + (c))
56
Ben Skeggs816af2f2011-11-16 15:48:48 +100057/* offsets in shared sync bo of various structures */
58#define EVO_SYNC(c, o) ((c) * 0x0100 + (o))
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +100059#define EVO_MAST_NTFY EVO_SYNC( 0, 0x00)
60#define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00)
61#define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10)
Ben Skeggs816af2f2011-11-16 15:48:48 +100062
Ben Skeggsb5a794b2012-10-16 14:18:32 +100063#define EVO_CORE_HANDLE (0xd1500000)
64#define EVO_CHAN_HANDLE(t,i) (0xd15c0000 | (((t) & 0x00ff) << 8) | (i))
65#define EVO_CHAN_OCLASS(t,c) ((nv_hclass(c) & 0xff00) | ((t) & 0x00ff))
66#define EVO_PUSH_HANDLE(t,i) (0xd15b0000 | (i) | \
67 (((NV50_DISP_##t##_CLASS) & 0x00ff) << 8))
68
69/******************************************************************************
70 * EVO channel
71 *****************************************************************************/
72
Ben Skeggse225f442012-11-21 14:40:21 +100073struct nv50_chan {
Ben Skeggsb5a794b2012-10-16 14:18:32 +100074 struct nouveau_object *user;
75 u32 handle;
76};
77
78static int
Ben Skeggse225f442012-11-21 14:40:21 +100079nv50_chan_create(struct nouveau_object *core, u32 bclass, u8 head,
80 void *data, u32 size, struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +100081{
82 struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
83 const u32 oclass = EVO_CHAN_OCLASS(bclass, core);
84 const u32 handle = EVO_CHAN_HANDLE(bclass, head);
85 int ret;
86
87 ret = nouveau_object_new(client, EVO_CORE_HANDLE, handle,
88 oclass, data, size, &chan->user);
89 if (ret)
90 return ret;
91
92 chan->handle = handle;
93 return 0;
94}
95
96static void
Ben Skeggse225f442012-11-21 14:40:21 +100097nv50_chan_destroy(struct nouveau_object *core, struct nv50_chan *chan)
Ben Skeggsb5a794b2012-10-16 14:18:32 +100098{
99 struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
100 if (chan->handle)
101 nouveau_object_del(client, EVO_CORE_HANDLE, chan->handle);
102}
103
104/******************************************************************************
105 * PIO EVO channel
106 *****************************************************************************/
107
Ben Skeggse225f442012-11-21 14:40:21 +1000108struct nv50_pioc {
109 struct nv50_chan base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000110};
111
112static void
Ben Skeggse225f442012-11-21 14:40:21 +1000113nv50_pioc_destroy(struct nouveau_object *core, struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000114{
Ben Skeggse225f442012-11-21 14:40:21 +1000115 nv50_chan_destroy(core, &pioc->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000116}
117
118static int
Ben Skeggse225f442012-11-21 14:40:21 +1000119nv50_pioc_create(struct nouveau_object *core, u32 bclass, u8 head,
120 void *data, u32 size, struct nv50_pioc *pioc)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000121{
Ben Skeggse225f442012-11-21 14:40:21 +1000122 return nv50_chan_create(core, bclass, head, data, size, &pioc->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000123}
124
125/******************************************************************************
126 * DMA EVO channel
127 *****************************************************************************/
128
Ben Skeggse225f442012-11-21 14:40:21 +1000129struct nv50_dmac {
130 struct nv50_chan base;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000131 dma_addr_t handle;
132 u32 *ptr;
Daniel Vetter59ad1462012-12-02 14:49:44 +0100133
134 /* Protects against concurrent pushbuf access to this channel, lock is
135 * grabbed by evo_wait (if the pushbuf reservation is successful) and
136 * dropped again by evo_kick. */
137 struct mutex lock;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000138};
139
140static void
Ben Skeggse225f442012-11-21 14:40:21 +1000141nv50_dmac_destroy(struct nouveau_object *core, struct nv50_dmac *dmac)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000142{
143 if (dmac->ptr) {
144 struct pci_dev *pdev = nv_device(core)->pdev;
145 pci_free_consistent(pdev, PAGE_SIZE, dmac->ptr, dmac->handle);
146 }
147
Ben Skeggse225f442012-11-21 14:40:21 +1000148 nv50_chan_destroy(core, &dmac->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000149}
150
151static int
Ben Skeggse225f442012-11-21 14:40:21 +1000152nv50_dmac_create(struct nouveau_object *core, u32 bclass, u8 head,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000153 void *data, u32 size, u64 syncbuf,
Ben Skeggse225f442012-11-21 14:40:21 +1000154 struct nv50_dmac *dmac)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000155{
156 struct nouveau_fb *pfb = nouveau_fb(core);
157 struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS);
158 struct nouveau_object *object;
159 u32 pushbuf = *(u32 *)data;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000160 int ret;
161
Daniel Vetter59ad1462012-12-02 14:49:44 +0100162 mutex_init(&dmac->lock);
163
Ben Skeggs47057302012-11-16 13:58:48 +1000164 dmac->ptr = pci_alloc_consistent(nv_device(core)->pdev, PAGE_SIZE,
165 &dmac->handle);
166 if (!dmac->ptr)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000167 return -ENOMEM;
168
169 ret = nouveau_object_new(client, NVDRM_DEVICE, pushbuf,
170 NV_DMA_FROM_MEMORY_CLASS,
171 &(struct nv_dma_class) {
172 .flags = NV_DMA_TARGET_PCI_US |
173 NV_DMA_ACCESS_RD,
Ben Skeggs47057302012-11-16 13:58:48 +1000174 .start = dmac->handle + 0x0000,
175 .limit = dmac->handle + 0x0fff,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000176 }, sizeof(struct nv_dma_class), &object);
177 if (ret)
178 return ret;
179
Ben Skeggse225f442012-11-21 14:40:21 +1000180 ret = nv50_chan_create(core, bclass, head, data, size, &dmac->base);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000181 if (ret)
182 return ret;
183
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000184 ret = nouveau_object_new(client, dmac->base.handle, NvEvoSync,
185 NV_DMA_IN_MEMORY_CLASS,
186 &(struct nv_dma_class) {
187 .flags = NV_DMA_TARGET_VRAM |
188 NV_DMA_ACCESS_RDWR,
189 .start = syncbuf + 0x0000,
190 .limit = syncbuf + 0x0fff,
191 }, sizeof(struct nv_dma_class), &object);
192 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000193 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000194
195 ret = nouveau_object_new(client, dmac->base.handle, NvEvoVRAM,
196 NV_DMA_IN_MEMORY_CLASS,
197 &(struct nv_dma_class) {
198 .flags = NV_DMA_TARGET_VRAM |
199 NV_DMA_ACCESS_RDWR,
200 .start = 0,
Ben Skeggsdceef5d2013-03-04 13:01:21 +1000201 .limit = pfb->ram->size - 1,
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000202 }, sizeof(struct nv_dma_class), &object);
203 if (ret)
Ben Skeggs47057302012-11-16 13:58:48 +1000204 return ret;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000205
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000206 return ret;
207}
208
Ben Skeggse225f442012-11-21 14:40:21 +1000209struct nv50_mast {
210 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000211};
212
Ben Skeggse225f442012-11-21 14:40:21 +1000213struct nv50_curs {
214 struct nv50_pioc base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000215};
216
Ben Skeggse225f442012-11-21 14:40:21 +1000217struct nv50_sync {
218 struct nv50_dmac base;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000219 u32 addr;
220 u32 data;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000221};
222
Ben Skeggse225f442012-11-21 14:40:21 +1000223struct nv50_ovly {
224 struct nv50_dmac base;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000225};
Ben Skeggsf20ce962011-07-08 13:17:01 +1000226
Ben Skeggse225f442012-11-21 14:40:21 +1000227struct nv50_oimm {
228 struct nv50_pioc base;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000229};
230
Ben Skeggse225f442012-11-21 14:40:21 +1000231struct nv50_head {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000232 struct nouveau_crtc base;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000233 struct nouveau_bo *image;
Ben Skeggse225f442012-11-21 14:40:21 +1000234 struct nv50_curs curs;
235 struct nv50_sync sync;
236 struct nv50_ovly ovly;
237 struct nv50_oimm oimm;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000238};
239
Ben Skeggse225f442012-11-21 14:40:21 +1000240#define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c))
241#define nv50_curs(c) (&nv50_head(c)->curs)
242#define nv50_sync(c) (&nv50_head(c)->sync)
243#define nv50_ovly(c) (&nv50_head(c)->ovly)
244#define nv50_oimm(c) (&nv50_head(c)->oimm)
245#define nv50_chan(c) (&(c)->base.base)
246#define nv50_vers(c) nv_mclass(nv50_chan(c)->user)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000247
Ben Skeggse225f442012-11-21 14:40:21 +1000248struct nv50_disp {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000249 struct nouveau_object *core;
Ben Skeggse225f442012-11-21 14:40:21 +1000250 struct nv50_mast mast;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000251
Ben Skeggs8a423642014-08-10 04:10:19 +1000252 struct list_head fbdma;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000253
254 struct nouveau_bo *sync;
Ben Skeggsdd0e3d52012-10-16 14:00:31 +1000255};
256
Ben Skeggse225f442012-11-21 14:40:21 +1000257static struct nv50_disp *
258nv50_disp(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +1000259{
Ben Skeggs77145f12012-07-31 16:16:21 +1000260 return nouveau_display(dev)->priv;
Ben Skeggs26f6d882011-07-04 16:25:18 +1000261}
262
Ben Skeggse225f442012-11-21 14:40:21 +1000263#define nv50_mast(d) (&nv50_disp(d)->mast)
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000264
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000265static struct drm_crtc *
Ben Skeggse225f442012-11-21 14:40:21 +1000266nv50_display_crtc_get(struct drm_encoder *encoder)
Ben Skeggsbdb8c212011-11-12 01:30:24 +1000267{
268 return nouveau_encoder(encoder)->crtc;
269}
270
271/******************************************************************************
272 * EVO channel helpers
273 *****************************************************************************/
Ben Skeggs51beb422011-07-05 10:33:08 +1000274static u32 *
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000275evo_wait(void *evoc, int nr)
Ben Skeggs51beb422011-07-05 10:33:08 +1000276{
Ben Skeggse225f442012-11-21 14:40:21 +1000277 struct nv50_dmac *dmac = evoc;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000278 u32 put = nv_ro32(dmac->base.user, 0x0000) / 4;
Ben Skeggs51beb422011-07-05 10:33:08 +1000279
Daniel Vetter59ad1462012-12-02 14:49:44 +0100280 mutex_lock(&dmac->lock);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000281 if (put + nr >= (PAGE_SIZE / 4) - 8) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000282 dmac->ptr[put] = 0x20000000;
Ben Skeggs51beb422011-07-05 10:33:08 +1000283
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000284 nv_wo32(dmac->base.user, 0x0000, 0x00000000);
285 if (!nv_wait(dmac->base.user, 0x0004, ~0, 0x00000000)) {
Daniel Vetter59ad1462012-12-02 14:49:44 +0100286 mutex_unlock(&dmac->lock);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000287 NV_ERROR(dmac->base.user, "channel stalled\n");
Ben Skeggs51beb422011-07-05 10:33:08 +1000288 return NULL;
289 }
290
291 put = 0;
292 }
293
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000294 return dmac->ptr + put;
Ben Skeggs51beb422011-07-05 10:33:08 +1000295}
296
297static void
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000298evo_kick(u32 *push, void *evoc)
Ben Skeggs51beb422011-07-05 10:33:08 +1000299{
Ben Skeggse225f442012-11-21 14:40:21 +1000300 struct nv50_dmac *dmac = evoc;
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000301 nv_wo32(dmac->base.user, 0x0000, (push - dmac->ptr) << 2);
Daniel Vetter59ad1462012-12-02 14:49:44 +0100302 mutex_unlock(&dmac->lock);
Ben Skeggs51beb422011-07-05 10:33:08 +1000303}
304
305#define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m))
306#define evo_data(p,d) *((p)++) = (d)
307
Ben Skeggs3376ee32011-11-12 14:28:12 +1000308static bool
309evo_sync_wait(void *data)
310{
Ben Skeggs5cc027f2013-02-18 17:50:51 -0500311 if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000)
312 return true;
313 usleep_range(1, 2);
314 return false;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000315}
316
317static int
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000318evo_sync(struct drm_device *dev)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000319{
Ben Skeggs77145f12012-07-31 16:16:21 +1000320 struct nouveau_device *device = nouveau_dev(dev);
Ben Skeggse225f442012-11-21 14:40:21 +1000321 struct nv50_disp *disp = nv50_disp(dev);
322 struct nv50_mast *mast = nv50_mast(dev);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000323 u32 *push = evo_wait(mast, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000324 if (push) {
Ben Skeggs816af2f2011-11-16 15:48:48 +1000325 nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000326 evo_mthd(push, 0x0084, 1);
Ben Skeggs816af2f2011-11-16 15:48:48 +1000327 evo_data(push, 0x80000000 | EVO_MAST_NTFY);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000328 evo_mthd(push, 0x0080, 2);
329 evo_data(push, 0x00000000);
330 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000331 evo_kick(push, mast);
Ben Skeggs77145f12012-07-31 16:16:21 +1000332 if (nv_wait_cb(device, evo_sync_wait, disp->sync))
Ben Skeggs3376ee32011-11-12 14:28:12 +1000333 return 0;
334 }
335
336 return -EBUSY;
337}
338
339/******************************************************************************
Ben Skeggsa63a97e2011-11-16 15:22:34 +1000340 * Page flipping channel
Ben Skeggs3376ee32011-11-12 14:28:12 +1000341 *****************************************************************************/
342struct nouveau_bo *
Ben Skeggse225f442012-11-21 14:40:21 +1000343nv50_display_crtc_sema(struct drm_device *dev, int crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000344{
Ben Skeggse225f442012-11-21 14:40:21 +1000345 return nv50_disp(dev)->sync;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000346}
347
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000348struct nv50_display_flip {
349 struct nv50_disp *disp;
350 struct nv50_sync *chan;
351};
352
353static bool
354nv50_display_flip_wait(void *data)
355{
356 struct nv50_display_flip *flip = data;
357 if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) ==
Calvin Owensb1ea3e62013-04-07 21:01:19 -0500358 flip->chan->data)
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000359 return true;
360 usleep_range(1, 2);
361 return false;
362}
363
Ben Skeggs3376ee32011-11-12 14:28:12 +1000364void
Ben Skeggse225f442012-11-21 14:40:21 +1000365nv50_display_flip_stop(struct drm_crtc *crtc)
Ben Skeggs3376ee32011-11-12 14:28:12 +1000366{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000367 struct nouveau_device *device = nouveau_dev(crtc->dev);
368 struct nv50_display_flip flip = {
369 .disp = nv50_disp(crtc->dev),
370 .chan = nv50_sync(crtc),
371 };
Ben Skeggs3376ee32011-11-12 14:28:12 +1000372 u32 *push;
373
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000374 push = evo_wait(flip.chan, 8);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000375 if (push) {
376 evo_mthd(push, 0x0084, 1);
377 evo_data(push, 0x00000000);
378 evo_mthd(push, 0x0094, 1);
379 evo_data(push, 0x00000000);
380 evo_mthd(push, 0x00c0, 1);
381 evo_data(push, 0x00000000);
382 evo_mthd(push, 0x0080, 1);
383 evo_data(push, 0x00000000);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000384 evo_kick(push, flip.chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000385 }
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000386
387 nv_wait_cb(device, nv50_display_flip_wait, &flip);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000388}
389
390int
Ben Skeggse225f442012-11-21 14:40:21 +1000391nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb,
Ben Skeggs3376ee32011-11-12 14:28:12 +1000392 struct nouveau_channel *chan, u32 swap_interval)
393{
394 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000395 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000396 struct nv50_head *head = nv50_head(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000397 struct nv50_sync *sync = nv50_sync(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000398 u32 *push;
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000399 int ret;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000400
401 swap_interval <<= 4;
402 if (swap_interval == 0)
403 swap_interval |= 0x100;
Ben Skeggsf60b6e72013-03-19 15:20:00 +1000404 if (chan == NULL)
405 evo_sync(crtc->dev);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000406
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000407 push = evo_wait(sync, 128);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000408 if (unlikely(push == NULL))
409 return -EBUSY;
410
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000411 if (chan && nv_mclass(chan->object) < NV84_CHANNEL_IND_CLASS) {
412 ret = RING_SPACE(chan, 8);
413 if (ret)
414 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000415
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000416 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000417 OUT_RING (chan, NvEvoSema0 + nv_crtc->index);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000418 OUT_RING (chan, sync->addr ^ 0x10);
419 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1);
420 OUT_RING (chan, sync->data + 1);
421 BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2);
422 OUT_RING (chan, sync->addr);
423 OUT_RING (chan, sync->data);
424 } else
425 if (chan && nv_mclass(chan->object) < NVC0_CHANNEL_IND_CLASS) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000426 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000427 ret = RING_SPACE(chan, 12);
428 if (ret)
429 return ret;
Ben Skeggsa34caf72013-02-14 09:28:37 +1000430
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000431 BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1);
432 OUT_RING (chan, chan->vram);
433 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
434 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
435 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
436 OUT_RING (chan, sync->data + 1);
437 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG);
438 BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
439 OUT_RING (chan, upper_32_bits(addr));
440 OUT_RING (chan, lower_32_bits(addr));
441 OUT_RING (chan, sync->data);
442 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL);
443 } else
444 if (chan) {
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000445 u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr;
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000446 ret = RING_SPACE(chan, 10);
447 if (ret)
448 return ret;
Ben Skeggs67f97182013-02-26 12:02:54 +1000449
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000450 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
451 OUT_RING (chan, upper_32_bits(addr ^ 0x10));
452 OUT_RING (chan, lower_32_bits(addr ^ 0x10));
453 OUT_RING (chan, sync->data + 1);
454 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG |
455 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
456 BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4);
457 OUT_RING (chan, upper_32_bits(addr));
458 OUT_RING (chan, lower_32_bits(addr));
459 OUT_RING (chan, sync->data);
460 OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL |
461 NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD);
462 }
Ben Skeggs35bcf5d2012-04-30 11:34:10 -0500463
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000464 if (chan) {
465 sync->addr ^= 0x10;
466 sync->data++;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000467 FIRE_RING (chan);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000468 }
469
470 /* queue the flip */
471 evo_mthd(push, 0x0100, 1);
472 evo_data(push, 0xfffe0000);
473 evo_mthd(push, 0x0084, 1);
474 evo_data(push, swap_interval);
475 if (!(swap_interval & 0x00000100)) {
476 evo_mthd(push, 0x00e0, 1);
477 evo_data(push, 0x40000000);
478 }
479 evo_mthd(push, 0x0088, 4);
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +1000480 evo_data(push, sync->addr);
481 evo_data(push, sync->data++);
482 evo_data(push, sync->data);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000483 evo_data(push, NvEvoSync);
484 evo_mthd(push, 0x00a0, 2);
485 evo_data(push, 0x00000000);
486 evo_data(push, 0x00000000);
487 evo_mthd(push, 0x00c0, 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000488 evo_data(push, nv_fb->r_handle);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000489 evo_mthd(push, 0x0110, 2);
490 evo_data(push, 0x00000000);
491 evo_data(push, 0x00000000);
Ben Skeggse225f442012-11-21 14:40:21 +1000492 if (nv50_vers(sync) < NVD0_DISP_SYNC_CLASS) {
Ben Skeggsed5085a52012-11-16 13:16:51 +1000493 evo_mthd(push, 0x0800, 5);
494 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
495 evo_data(push, 0);
496 evo_data(push, (fb->height << 16) | fb->width);
497 evo_data(push, nv_fb->r_pitch);
498 evo_data(push, nv_fb->r_format);
499 } else {
500 evo_mthd(push, 0x0400, 5);
501 evo_data(push, nv_fb->nvbo->bo.offset >> 8);
502 evo_data(push, 0);
503 evo_data(push, (fb->height << 16) | fb->width);
504 evo_data(push, nv_fb->r_pitch);
505 evo_data(push, nv_fb->r_format);
506 }
Ben Skeggs3376ee32011-11-12 14:28:12 +1000507 evo_mthd(push, 0x0080, 1);
508 evo_data(push, 0x00000000);
Ben Skeggsb5a794b2012-10-16 14:18:32 +1000509 evo_kick(push, sync);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000510
511 nouveau_bo_ref(nv_fb->nvbo, &head->image);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000512 return 0;
513}
514
Ben Skeggs26f6d882011-07-04 16:25:18 +1000515/******************************************************************************
Ben Skeggs438d99e2011-07-05 16:48:06 +1000516 * CRTC
517 *****************************************************************************/
518static int
Ben Skeggse225f442012-11-21 14:40:21 +1000519nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000520{
Ben Skeggse225f442012-11-21 14:40:21 +1000521 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde691852011-10-17 12:23:41 +1000522 struct nouveau_connector *nv_connector;
523 struct drm_connector *connector;
524 u32 *push, mode = 0x00;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000525
Ben Skeggs488ff202011-10-17 10:38:10 +1000526 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggsde691852011-10-17 12:23:41 +1000527 connector = &nv_connector->base;
528 if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) {
Matt Roperf4510a22014-04-01 15:22:40 -0700529 if (nv_crtc->base.primary->fb->depth > connector->display_info.bpc * 3)
Ben Skeggsde691852011-10-17 12:23:41 +1000530 mode = DITHERING_MODE_DYNAMIC2X2;
531 } else {
532 mode = nv_connector->dithering_mode;
533 }
534
535 if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) {
536 if (connector->display_info.bpc >= 8)
537 mode |= DITHERING_DEPTH_8BPC;
538 } else {
539 mode |= nv_connector->dithering_depth;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000540 }
541
Ben Skeggsde8268c2012-11-16 10:24:31 +1000542 push = evo_wait(mast, 4);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000543 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000544 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000545 evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1);
546 evo_data(push, mode);
547 } else
Ben Skeggse225f442012-11-21 14:40:21 +1000548 if (nv50_vers(mast) < NVE0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000549 evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1);
550 evo_data(push, mode);
551 } else {
552 evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1);
553 evo_data(push, mode);
554 }
555
Ben Skeggs438d99e2011-07-05 16:48:06 +1000556 if (update) {
557 evo_mthd(push, 0x0080, 1);
558 evo_data(push, 0x00000000);
559 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000560 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000561 }
562
563 return 0;
564}
565
566static int
Ben Skeggse225f442012-11-21 14:40:21 +1000567nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000568{
Ben Skeggse225f442012-11-21 14:40:21 +1000569 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs92854622011-11-11 23:49:06 +1000570 struct drm_display_mode *omode, *umode = &nv_crtc->base.mode;
Ben Skeggs3376ee32011-11-12 14:28:12 +1000571 struct drm_crtc *crtc = &nv_crtc->base;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000572 struct nouveau_connector *nv_connector;
Ben Skeggs92854622011-11-11 23:49:06 +1000573 int mode = DRM_MODE_SCALE_NONE;
574 u32 oX, oY, *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000575
Ben Skeggs92854622011-11-11 23:49:06 +1000576 /* start off at the resolution we programmed the crtc for, this
577 * effectively handles NONE/FULL scaling
578 */
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000579 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggs92854622011-11-11 23:49:06 +1000580 if (nv_connector && nv_connector->native_mode)
581 mode = nv_connector->scaling_mode;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000582
Ben Skeggs92854622011-11-11 23:49:06 +1000583 if (mode != DRM_MODE_SCALE_NONE)
584 omode = nv_connector->native_mode;
585 else
586 omode = umode;
587
588 oX = omode->hdisplay;
589 oY = omode->vdisplay;
590 if (omode->flags & DRM_MODE_FLAG_DBLSCAN)
591 oY *= 2;
592
593 /* add overscan compensation if necessary, will keep the aspect
594 * ratio the same as the backend mode unless overridden by the
595 * user setting both hborder and vborder properties.
596 */
597 if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON ||
598 (nv_connector->underscan == UNDERSCAN_AUTO &&
599 nv_connector->edid &&
600 drm_detect_hdmi_monitor(nv_connector->edid)))) {
601 u32 bX = nv_connector->underscan_hborder;
602 u32 bY = nv_connector->underscan_vborder;
603 u32 aspect = (oY << 19) / oX;
604
605 if (bX) {
606 oX -= (bX * 2);
607 if (bY) oY -= (bY * 2);
608 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
609 } else {
610 oX -= (oX >> 4) + 32;
611 if (bY) oY -= (bY * 2);
612 else oY = ((oX * aspect) + (aspect / 2)) >> 19;
Ben Skeggsf3fdc522011-07-07 16:01:57 +1000613 }
614 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000615
Ben Skeggs92854622011-11-11 23:49:06 +1000616 /* handle CENTER/ASPECT scaling, taking into account the areas
617 * removed already for overscan compensation
618 */
619 switch (mode) {
620 case DRM_MODE_SCALE_CENTER:
621 oX = min((u32)umode->hdisplay, oX);
622 oY = min((u32)umode->vdisplay, oY);
623 /* fall-through */
624 case DRM_MODE_SCALE_ASPECT:
625 if (oY < oX) {
626 u32 aspect = (umode->hdisplay << 19) / umode->vdisplay;
627 oX = ((oY * aspect) + (aspect / 2)) >> 19;
628 } else {
629 u32 aspect = (umode->vdisplay << 19) / umode->hdisplay;
630 oY = ((oX * aspect) + (aspect / 2)) >> 19;
631 }
632 break;
633 default:
634 break;
635 }
636
Ben Skeggsde8268c2012-11-16 10:24:31 +1000637 push = evo_wait(mast, 8);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000638 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000639 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000640 /*XXX: SCALE_CTRL_ACTIVE??? */
641 evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2);
642 evo_data(push, (oY << 16) | oX);
643 evo_data(push, (oY << 16) | oX);
644 evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1);
645 evo_data(push, 0x00000000);
646 evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1);
647 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
648 } else {
649 evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3);
650 evo_data(push, (oY << 16) | oX);
651 evo_data(push, (oY << 16) | oX);
652 evo_data(push, (oY << 16) | oX);
653 evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1);
654 evo_data(push, 0x00000000);
655 evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1);
656 evo_data(push, umode->vdisplay << 16 | umode->hdisplay);
657 }
658
659 evo_kick(push, mast);
660
Ben Skeggs3376ee32011-11-12 14:28:12 +1000661 if (update) {
Ben Skeggse225f442012-11-21 14:40:21 +1000662 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -0700663 nv50_display_flip_next(crtc, crtc->primary->fb,
664 NULL, 1);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000665 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000666 }
667
668 return 0;
669}
670
671static int
Ben Skeggse225f442012-11-21 14:40:21 +1000672nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update)
Ben Skeggsf9887d02012-11-21 13:03:42 +1000673{
Ben Skeggse225f442012-11-21 14:40:21 +1000674 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsf9887d02012-11-21 13:03:42 +1000675 u32 *push, hue, vib;
676 int adj;
677
678 adj = (nv_crtc->color_vibrance > 0) ? 50 : 0;
679 vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff;
680 hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff;
681
682 push = evo_wait(mast, 16);
683 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000684 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsf9887d02012-11-21 13:03:42 +1000685 evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1);
686 evo_data(push, (hue << 20) | (vib << 8));
687 } else {
688 evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1);
689 evo_data(push, (hue << 20) | (vib << 8));
690 }
691
692 if (update) {
693 evo_mthd(push, 0x0080, 1);
694 evo_data(push, 0x00000000);
695 }
696 evo_kick(push, mast);
697 }
698
699 return 0;
700}
701
702static int
Ben Skeggse225f442012-11-21 14:40:21 +1000703nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000704 int x, int y, bool update)
705{
706 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb);
Ben Skeggse225f442012-11-21 14:40:21 +1000707 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000708 u32 *push;
709
Ben Skeggsde8268c2012-11-16 10:24:31 +1000710 push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000711 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000712 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000713 evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1);
714 evo_data(push, nvfb->nvbo->bo.offset >> 8);
715 evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3);
716 evo_data(push, (fb->height << 16) | fb->width);
717 evo_data(push, nvfb->r_pitch);
718 evo_data(push, nvfb->r_format);
719 evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1);
720 evo_data(push, (y << 16) | x);
Ben Skeggse225f442012-11-21 14:40:21 +1000721 if (nv50_vers(mast) > NV50_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000722 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000723 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000724 }
725 } else {
726 evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1);
727 evo_data(push, nvfb->nvbo->bo.offset >> 8);
728 evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4);
729 evo_data(push, (fb->height << 16) | fb->width);
730 evo_data(push, nvfb->r_pitch);
731 evo_data(push, nvfb->r_format);
Ben Skeggs8a423642014-08-10 04:10:19 +1000732 evo_data(push, nvfb->r_handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000733 evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1);
734 evo_data(push, (y << 16) | x);
735 }
736
Ben Skeggsa46232e2011-07-07 15:23:48 +1000737 if (update) {
738 evo_mthd(push, 0x0080, 1);
739 evo_data(push, 0x00000000);
740 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000741 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000742 }
743
Ben Skeggs8a423642014-08-10 04:10:19 +1000744 nv_crtc->fb.handle = nvfb->r_handle;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000745 return 0;
746}
747
748static void
Ben Skeggse225f442012-11-21 14:40:21 +1000749nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000750{
Ben Skeggse225f442012-11-21 14:40:21 +1000751 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000752 u32 *push = evo_wait(mast, 16);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000753 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000754 if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000755 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
756 evo_data(push, 0x85000000);
757 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
758 } else
Ben Skeggse225f442012-11-21 14:40:21 +1000759 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000760 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2);
761 evo_data(push, 0x85000000);
762 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
763 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
764 evo_data(push, NvEvoVRAM);
765 } else {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000766 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2);
767 evo_data(push, 0x85000000);
768 evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8);
769 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
Ben Skeggs37b034a2011-07-08 14:43:19 +1000770 evo_data(push, NvEvoVRAM);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000771 }
772 evo_kick(push, mast);
773 }
774}
775
776static void
Ben Skeggse225f442012-11-21 14:40:21 +1000777nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000778{
Ben Skeggse225f442012-11-21 14:40:21 +1000779 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000780 u32 *push = evo_wait(mast, 16);
781 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000782 if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000783 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
784 evo_data(push, 0x05000000);
785 } else
Ben Skeggse225f442012-11-21 14:40:21 +1000786 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000787 evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1);
788 evo_data(push, 0x05000000);
789 evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1);
790 evo_data(push, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000791 } else {
792 evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1);
793 evo_data(push, 0x05000000);
794 evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1);
795 evo_data(push, 0x00000000);
796 }
Ben Skeggsde8268c2012-11-16 10:24:31 +1000797 evo_kick(push, mast);
798 }
799}
Ben Skeggs438d99e2011-07-05 16:48:06 +1000800
Ben Skeggsde8268c2012-11-16 10:24:31 +1000801static void
Ben Skeggse225f442012-11-21 14:40:21 +1000802nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update)
Ben Skeggsde8268c2012-11-16 10:24:31 +1000803{
Ben Skeggse225f442012-11-21 14:40:21 +1000804 struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000805
806 if (show)
Ben Skeggse225f442012-11-21 14:40:21 +1000807 nv50_crtc_cursor_show(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000808 else
Ben Skeggse225f442012-11-21 14:40:21 +1000809 nv50_crtc_cursor_hide(nv_crtc);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000810
811 if (update) {
812 u32 *push = evo_wait(mast, 2);
813 if (push) {
Ben Skeggs438d99e2011-07-05 16:48:06 +1000814 evo_mthd(push, 0x0080, 1);
815 evo_data(push, 0x00000000);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000816 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000817 }
Ben Skeggs438d99e2011-07-05 16:48:06 +1000818 }
819}
820
821static void
Ben Skeggse225f442012-11-21 14:40:21 +1000822nv50_crtc_dpms(struct drm_crtc *crtc, int mode)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000823{
824}
825
826static void
Ben Skeggse225f442012-11-21 14:40:21 +1000827nv50_crtc_prepare(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000828{
829 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000830 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000831 u32 *push;
832
Ben Skeggse225f442012-11-21 14:40:21 +1000833 nv50_display_flip_stop(crtc);
Ben Skeggs3376ee32011-11-12 14:28:12 +1000834
Ben Skeggs56d237d2014-05-19 14:54:33 +1000835 push = evo_wait(mast, 6);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000836 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000837 if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000838 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
839 evo_data(push, 0x00000000);
840 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
841 evo_data(push, 0x40000000);
842 } else
Ben Skeggse225f442012-11-21 14:40:21 +1000843 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000844 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
845 evo_data(push, 0x00000000);
846 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1);
847 evo_data(push, 0x40000000);
848 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
849 evo_data(push, 0x00000000);
850 } else {
851 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
852 evo_data(push, 0x00000000);
853 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1);
854 evo_data(push, 0x03000000);
855 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
856 evo_data(push, 0x00000000);
857 }
858
859 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000860 }
861
Ben Skeggse225f442012-11-21 14:40:21 +1000862 nv50_crtc_cursor_show_hide(nv_crtc, false, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000863}
864
865static void
Ben Skeggse225f442012-11-21 14:40:21 +1000866nv50_crtc_commit(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000867{
868 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +1000869 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000870 u32 *push;
871
Ben Skeggsde8268c2012-11-16 10:24:31 +1000872 push = evo_wait(mast, 32);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000873 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000874 if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000875 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000876 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000877 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
878 evo_data(push, 0xc0000000);
879 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
880 } else
Ben Skeggse225f442012-11-21 14:40:21 +1000881 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000882 evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000883 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000884 evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2);
885 evo_data(push, 0xc0000000);
886 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
887 evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1);
888 evo_data(push, NvEvoVRAM);
889 } else {
890 evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1);
Ben Skeggs8a423642014-08-10 04:10:19 +1000891 evo_data(push, nv_crtc->fb.handle);
Ben Skeggsde8268c2012-11-16 10:24:31 +1000892 evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4);
893 evo_data(push, 0x83000000);
894 evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8);
895 evo_data(push, 0x00000000);
896 evo_data(push, 0x00000000);
897 evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1);
898 evo_data(push, NvEvoVRAM);
899 evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1);
900 evo_data(push, 0xffffff00);
901 }
902
903 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000904 }
905
Ben Skeggse225f442012-11-21 14:40:21 +1000906 nv50_crtc_cursor_show_hide(nv_crtc, nv_crtc->cursor.visible, true);
Matt Roperf4510a22014-04-01 15:22:40 -0700907 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000908}
909
910static bool
Ben Skeggse225f442012-11-21 14:40:21 +1000911nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000912 struct drm_display_mode *adjusted_mode)
913{
Ben Skeggseb2e9682014-01-24 10:13:23 +1000914 drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000915 return true;
916}
917
918static int
Ben Skeggse225f442012-11-21 14:40:21 +1000919nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb)
Ben Skeggs438d99e2011-07-05 16:48:06 +1000920{
Matt Roperf4510a22014-04-01 15:22:40 -0700921 struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000922 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000923 int ret;
924
925 ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM);
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000926 if (ret == 0) {
927 if (head->image)
928 nouveau_bo_unpin(head->image);
929 nouveau_bo_ref(nvfb->nvbo, &head->image);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000930 }
931
Ben Skeggs8dda53f2013-07-09 12:35:55 +1000932 return ret;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000933}
934
935static int
Ben Skeggse225f442012-11-21 14:40:21 +1000936nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode,
Ben Skeggs438d99e2011-07-05 16:48:06 +1000937 struct drm_display_mode *mode, int x, int y,
938 struct drm_framebuffer *old_fb)
939{
Ben Skeggse225f442012-11-21 14:40:21 +1000940 struct nv50_mast *mast = nv50_mast(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000941 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
942 struct nouveau_connector *nv_connector;
Ben Skeggs2d1d8982011-11-11 23:39:22 +1000943 u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1;
944 u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1;
945 u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks;
946 u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks;
947 u32 vblan2e = 0, vblan2s = 1;
Ben Skeggs3488c572012-03-12 11:42:20 +1000948 u32 *push;
Ben Skeggs438d99e2011-07-05 16:48:06 +1000949 int ret;
950
Ben Skeggs2d1d8982011-11-11 23:39:22 +1000951 hactive = mode->htotal;
952 hsynce = mode->hsync_end - mode->hsync_start - 1;
953 hbackp = mode->htotal - mode->hsync_end;
954 hblanke = hsynce + hbackp;
955 hfrontp = mode->hsync_start - mode->hdisplay;
956 hblanks = mode->htotal - hfrontp - 1;
957
958 vactive = mode->vtotal * vscan / ilace;
959 vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1;
960 vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace;
961 vblanke = vsynce + vbackp;
962 vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace;
963 vblanks = vactive - vfrontp - 1;
964 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
965 vblan2e = vactive + vsynce + vbackp;
966 vblan2s = vblan2e + (mode->vdisplay * vscan / ilace);
967 vactive = (vactive * 2) + 1;
Ben Skeggs2d1d8982011-11-11 23:39:22 +1000968 }
969
Ben Skeggse225f442012-11-21 14:40:21 +1000970 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000971 if (ret)
972 return ret;
973
Ben Skeggsde8268c2012-11-16 10:24:31 +1000974 push = evo_wait(mast, 64);
Ben Skeggs438d99e2011-07-05 16:48:06 +1000975 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +1000976 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggsde8268c2012-11-16 10:24:31 +1000977 evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2);
978 evo_data(push, 0x00800000 | mode->clock);
979 evo_data(push, (ilace == 2) ? 2 : 0);
980 evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6);
981 evo_data(push, 0x00000000);
982 evo_data(push, (vactive << 16) | hactive);
983 evo_data(push, ( vsynce << 16) | hsynce);
984 evo_data(push, (vblanke << 16) | hblanke);
985 evo_data(push, (vblanks << 16) | hblanks);
986 evo_data(push, (vblan2e << 16) | vblan2s);
987 evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1);
988 evo_data(push, 0x00000000);
989 evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2);
990 evo_data(push, 0x00000311);
991 evo_data(push, 0x00000100);
992 } else {
993 evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6);
994 evo_data(push, 0x00000000);
995 evo_data(push, (vactive << 16) | hactive);
996 evo_data(push, ( vsynce << 16) | hsynce);
997 evo_data(push, (vblanke << 16) | hblanke);
998 evo_data(push, (vblanks << 16) | hblanks);
999 evo_data(push, (vblan2e << 16) | vblan2s);
1000 evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1);
1001 evo_data(push, 0x00000000); /* ??? */
1002 evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3);
1003 evo_data(push, mode->clock * 1000);
1004 evo_data(push, 0x00200000); /* ??? */
1005 evo_data(push, mode->clock * 1000);
1006 evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2);
1007 evo_data(push, 0x00000311);
1008 evo_data(push, 0x00000100);
1009 }
1010
1011 evo_kick(push, mast);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001012 }
1013
1014 nv_connector = nouveau_crtc_connector_get(nv_crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001015 nv50_crtc_set_dither(nv_crtc, false);
1016 nv50_crtc_set_scale(nv_crtc, false);
1017 nv50_crtc_set_color_vibrance(nv_crtc, false);
Matt Roperf4510a22014-04-01 15:22:40 -07001018 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001019 return 0;
1020}
1021
1022static int
Ben Skeggse225f442012-11-21 14:40:21 +10001023nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001024 struct drm_framebuffer *old_fb)
1025{
Ben Skeggs77145f12012-07-31 16:16:21 +10001026 struct nouveau_drm *drm = nouveau_drm(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001027 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1028 int ret;
1029
Matt Roperf4510a22014-04-01 15:22:40 -07001030 if (!crtc->primary->fb) {
Ben Skeggs77145f12012-07-31 16:16:21 +10001031 NV_DEBUG(drm, "No FB bound\n");
Ben Skeggs84e2ad82011-08-26 09:40:39 +10001032 return 0;
1033 }
1034
Ben Skeggse225f442012-11-21 14:40:21 +10001035 ret = nv50_crtc_swap_fbs(crtc, old_fb);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001036 if (ret)
1037 return ret;
1038
Ben Skeggse225f442012-11-21 14:40:21 +10001039 nv50_display_flip_stop(crtc);
Matt Roperf4510a22014-04-01 15:22:40 -07001040 nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true);
1041 nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001042 return 0;
1043}
1044
1045static int
Ben Skeggse225f442012-11-21 14:40:21 +10001046nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001047 struct drm_framebuffer *fb, int x, int y,
1048 enum mode_set_atomic state)
1049{
1050 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001051 nv50_display_flip_stop(crtc);
1052 nv50_crtc_set_image(nv_crtc, fb, x, y, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001053 return 0;
1054}
1055
1056static void
Ben Skeggse225f442012-11-21 14:40:21 +10001057nv50_crtc_lut_load(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001058{
Ben Skeggse225f442012-11-21 14:40:21 +10001059 struct nv50_disp *disp = nv50_disp(crtc->dev);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001060 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1061 void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo);
1062 int i;
1063
1064 for (i = 0; i < 256; i++) {
Ben Skeggsde8268c2012-11-16 10:24:31 +10001065 u16 r = nv_crtc->lut.r[i] >> 2;
1066 u16 g = nv_crtc->lut.g[i] >> 2;
1067 u16 b = nv_crtc->lut.b[i] >> 2;
1068
1069 if (nv_mclass(disp->core) < NVD0_DISP_CLASS) {
1070 writew(r + 0x0000, lut + (i * 0x08) + 0);
1071 writew(g + 0x0000, lut + (i * 0x08) + 2);
1072 writew(b + 0x0000, lut + (i * 0x08) + 4);
1073 } else {
1074 writew(r + 0x6000, lut + (i * 0x20) + 0);
1075 writew(g + 0x6000, lut + (i * 0x20) + 2);
1076 writew(b + 0x6000, lut + (i * 0x20) + 4);
1077 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001078 }
1079}
1080
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001081static void
1082nv50_crtc_disable(struct drm_crtc *crtc)
1083{
1084 struct nv50_head *head = nv50_head(crtc);
Ben Skeggsefa366f2014-06-05 12:56:35 +10001085 evo_sync(crtc->dev);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001086 if (head->image)
1087 nouveau_bo_unpin(head->image);
1088 nouveau_bo_ref(NULL, &head->image);
1089}
1090
Ben Skeggs438d99e2011-07-05 16:48:06 +10001091static int
Ben Skeggse225f442012-11-21 14:40:21 +10001092nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001093 uint32_t handle, uint32_t width, uint32_t height)
1094{
1095 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
1096 struct drm_device *dev = crtc->dev;
1097 struct drm_gem_object *gem;
1098 struct nouveau_bo *nvbo;
1099 bool visible = (handle != 0);
1100 int i, ret = 0;
1101
1102 if (visible) {
1103 if (width != 64 || height != 64)
1104 return -EINVAL;
1105
1106 gem = drm_gem_object_lookup(dev, file_priv, handle);
1107 if (unlikely(!gem))
1108 return -ENOENT;
1109 nvbo = nouveau_gem_object(gem);
1110
1111 ret = nouveau_bo_map(nvbo);
1112 if (ret == 0) {
1113 for (i = 0; i < 64 * 64; i++) {
1114 u32 v = nouveau_bo_rd32(nvbo, i);
1115 nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v);
1116 }
1117 nouveau_bo_unmap(nvbo);
1118 }
1119
1120 drm_gem_object_unreference_unlocked(gem);
1121 }
1122
1123 if (visible != nv_crtc->cursor.visible) {
Ben Skeggse225f442012-11-21 14:40:21 +10001124 nv50_crtc_cursor_show_hide(nv_crtc, visible, true);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001125 nv_crtc->cursor.visible = visible;
1126 }
1127
1128 return ret;
1129}
1130
1131static int
Ben Skeggse225f442012-11-21 14:40:21 +10001132nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001133{
Ben Skeggse225f442012-11-21 14:40:21 +10001134 struct nv50_curs *curs = nv50_curs(crtc);
1135 struct nv50_chan *chan = nv50_chan(curs);
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001136 nv_wo32(chan->user, 0x0084, (y << 16) | (x & 0xffff));
1137 nv_wo32(chan->user, 0x0080, 0x00000000);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001138 return 0;
1139}
1140
1141static void
Ben Skeggse225f442012-11-21 14:40:21 +10001142nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001143 uint32_t start, uint32_t size)
1144{
1145 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Dan Carpenterbdefc8c2013-11-28 01:18:47 +03001146 u32 end = min_t(u32, start + size, 256);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001147 u32 i;
1148
1149 for (i = start; i < end; i++) {
1150 nv_crtc->lut.r[i] = r[i];
1151 nv_crtc->lut.g[i] = g[i];
1152 nv_crtc->lut.b[i] = b[i];
1153 }
1154
Ben Skeggse225f442012-11-21 14:40:21 +10001155 nv50_crtc_lut_load(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001156}
1157
1158static void
Ben Skeggse225f442012-11-21 14:40:21 +10001159nv50_crtc_destroy(struct drm_crtc *crtc)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001160{
1161 struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc);
Ben Skeggse225f442012-11-21 14:40:21 +10001162 struct nv50_disp *disp = nv50_disp(crtc->dev);
1163 struct nv50_head *head = nv50_head(crtc);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001164
Ben Skeggse225f442012-11-21 14:40:21 +10001165 nv50_dmac_destroy(disp->core, &head->ovly.base);
1166 nv50_pioc_destroy(disp->core, &head->oimm.base);
1167 nv50_dmac_destroy(disp->core, &head->sync.base);
1168 nv50_pioc_destroy(disp->core, &head->curs.base);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001169
1170 /*XXX: this shouldn't be necessary, but the core doesn't call
1171 * disconnect() during the cleanup paths
1172 */
1173 if (head->image)
1174 nouveau_bo_unpin(head->image);
1175 nouveau_bo_ref(NULL, &head->image);
1176
Ben Skeggs438d99e2011-07-05 16:48:06 +10001177 nouveau_bo_unmap(nv_crtc->cursor.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001178 if (nv_crtc->cursor.nvbo)
1179 nouveau_bo_unpin(nv_crtc->cursor.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001180 nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001181
Ben Skeggs438d99e2011-07-05 16:48:06 +10001182 nouveau_bo_unmap(nv_crtc->lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001183 if (nv_crtc->lut.nvbo)
1184 nouveau_bo_unpin(nv_crtc->lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001185 nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo);
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001186
Ben Skeggs438d99e2011-07-05 16:48:06 +10001187 drm_crtc_cleanup(crtc);
1188 kfree(crtc);
1189}
1190
Ben Skeggse225f442012-11-21 14:40:21 +10001191static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = {
1192 .dpms = nv50_crtc_dpms,
1193 .prepare = nv50_crtc_prepare,
1194 .commit = nv50_crtc_commit,
1195 .mode_fixup = nv50_crtc_mode_fixup,
1196 .mode_set = nv50_crtc_mode_set,
1197 .mode_set_base = nv50_crtc_mode_set_base,
1198 .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic,
1199 .load_lut = nv50_crtc_lut_load,
Ben Skeggs8dda53f2013-07-09 12:35:55 +10001200 .disable = nv50_crtc_disable,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001201};
1202
Ben Skeggse225f442012-11-21 14:40:21 +10001203static const struct drm_crtc_funcs nv50_crtc_func = {
1204 .cursor_set = nv50_crtc_cursor_set,
1205 .cursor_move = nv50_crtc_cursor_move,
1206 .gamma_set = nv50_crtc_gamma_set,
Dave Airlie5addcf02012-09-10 14:20:51 +10001207 .set_config = nouveau_crtc_set_config,
Ben Skeggse225f442012-11-21 14:40:21 +10001208 .destroy = nv50_crtc_destroy,
Ben Skeggs3376ee32011-11-12 14:28:12 +10001209 .page_flip = nouveau_crtc_page_flip,
Ben Skeggs438d99e2011-07-05 16:48:06 +10001210};
1211
Ben Skeggsc20ab3e2011-08-25 14:09:43 +10001212static void
Ben Skeggse225f442012-11-21 14:40:21 +10001213nv50_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y)
Ben Skeggsc20ab3e2011-08-25 14:09:43 +10001214{
1215}
1216
1217static void
Ben Skeggse225f442012-11-21 14:40:21 +10001218nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset)
Ben Skeggsc20ab3e2011-08-25 14:09:43 +10001219{
1220}
1221
Ben Skeggs438d99e2011-07-05 16:48:06 +10001222static int
Ben Skeggse225f442012-11-21 14:40:21 +10001223nv50_crtc_create(struct drm_device *dev, struct nouveau_object *core, int index)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001224{
Ben Skeggse225f442012-11-21 14:40:21 +10001225 struct nv50_disp *disp = nv50_disp(dev);
1226 struct nv50_head *head;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001227 struct drm_crtc *crtc;
1228 int ret, i;
1229
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001230 head = kzalloc(sizeof(*head), GFP_KERNEL);
1231 if (!head)
Ben Skeggs438d99e2011-07-05 16:48:06 +10001232 return -ENOMEM;
1233
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001234 head->base.index = index;
Ben Skeggse225f442012-11-21 14:40:21 +10001235 head->base.set_dither = nv50_crtc_set_dither;
1236 head->base.set_scale = nv50_crtc_set_scale;
1237 head->base.set_color_vibrance = nv50_crtc_set_color_vibrance;
Ben Skeggsf9887d02012-11-21 13:03:42 +10001238 head->base.color_vibrance = 50;
1239 head->base.vibrant_hue = 0;
Ben Skeggse225f442012-11-21 14:40:21 +10001240 head->base.cursor.set_offset = nv50_cursor_set_offset;
1241 head->base.cursor.set_pos = nv50_cursor_set_pos;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001242 for (i = 0; i < 256; i++) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001243 head->base.lut.r[i] = i << 8;
1244 head->base.lut.g[i] = i << 8;
1245 head->base.lut.b[i] = i << 8;
Ben Skeggs438d99e2011-07-05 16:48:06 +10001246 }
1247
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001248 crtc = &head->base.base;
Ben Skeggse225f442012-11-21 14:40:21 +10001249 drm_crtc_init(dev, crtc, &nv50_crtc_func);
1250 drm_crtc_helper_add(crtc, &nv50_crtc_hfunc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001251 drm_mode_crtc_set_gamma_size(crtc, 256);
1252
Ben Skeggs8ea0d4a2011-07-07 14:49:24 +10001253 ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM,
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001254 0, 0x0000, NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001255 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001256 ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001257 if (!ret) {
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001258 ret = nouveau_bo_map(head->base.lut.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001259 if (ret)
1260 nouveau_bo_unpin(head->base.lut.nvbo);
1261 }
Ben Skeggs438d99e2011-07-05 16:48:06 +10001262 if (ret)
Ben Skeggsdd0e3d52012-10-16 14:00:31 +10001263 nouveau_bo_ref(NULL, &head->base.lut.nvbo);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001264 }
1265
1266 if (ret)
1267 goto out;
1268
Ben Skeggse225f442012-11-21 14:40:21 +10001269 nv50_crtc_lut_load(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001270
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001271 /* allocate cursor resources */
Ben Skeggse225f442012-11-21 14:40:21 +10001272 ret = nv50_pioc_create(disp->core, NV50_DISP_CURS_CLASS, index,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001273 &(struct nv50_display_curs_class) {
1274 .head = index,
1275 }, sizeof(struct nv50_display_curs_class),
1276 &head->curs.base);
1277 if (ret)
1278 goto out;
1279
1280 ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM,
1281 0, 0x0000, NULL, &head->base.cursor.nvbo);
1282 if (!ret) {
1283 ret = nouveau_bo_pin(head->base.cursor.nvbo, TTM_PL_FLAG_VRAM);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001284 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001285 ret = nouveau_bo_map(head->base.cursor.nvbo);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01001286 if (ret)
1287 nouveau_bo_unpin(head->base.lut.nvbo);
1288 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001289 if (ret)
1290 nouveau_bo_ref(NULL, &head->base.cursor.nvbo);
1291 }
1292
1293 if (ret)
1294 goto out;
1295
1296 /* allocate page flip / sync resources */
Ben Skeggse225f442012-11-21 14:40:21 +10001297 ret = nv50_dmac_create(disp->core, NV50_DISP_SYNC_CLASS, index,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001298 &(struct nv50_display_sync_class) {
1299 .pushbuf = EVO_PUSH_HANDLE(SYNC, index),
1300 .head = index,
1301 }, sizeof(struct nv50_display_sync_class),
1302 disp->sync->bo.offset, &head->sync.base);
1303 if (ret)
1304 goto out;
1305
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10001306 head->sync.addr = EVO_FLIP_SEM0(index);
1307 head->sync.data = 0x00000000;
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001308
1309 /* allocate overlay resources */
Ben Skeggse225f442012-11-21 14:40:21 +10001310 ret = nv50_pioc_create(disp->core, NV50_DISP_OIMM_CLASS, index,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001311 &(struct nv50_display_oimm_class) {
1312 .head = index,
1313 }, sizeof(struct nv50_display_oimm_class),
1314 &head->oimm.base);
1315 if (ret)
1316 goto out;
1317
Ben Skeggse225f442012-11-21 14:40:21 +10001318 ret = nv50_dmac_create(disp->core, NV50_DISP_OVLY_CLASS, index,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10001319 &(struct nv50_display_ovly_class) {
1320 .pushbuf = EVO_PUSH_HANDLE(OVLY, index),
1321 .head = index,
1322 }, sizeof(struct nv50_display_ovly_class),
1323 disp->sync->bo.offset, &head->ovly.base);
1324 if (ret)
1325 goto out;
1326
Ben Skeggs438d99e2011-07-05 16:48:06 +10001327out:
1328 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10001329 nv50_crtc_destroy(crtc);
Ben Skeggs438d99e2011-07-05 16:48:06 +10001330 return ret;
1331}
1332
1333/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001334 * DAC
1335 *****************************************************************************/
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001336static void
Ben Skeggse225f442012-11-21 14:40:21 +10001337nv50_dac_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001338{
1339 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001340 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001341 int or = nv_encoder->or;
1342 u32 dpms_ctrl;
1343
Ben Skeggs35b21d32012-11-08 12:08:55 +10001344 dpms_ctrl = 0x00000000;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001345 if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF)
1346 dpms_ctrl |= 0x00000001;
1347 if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF)
1348 dpms_ctrl |= 0x00000004;
1349
Ben Skeggs35b21d32012-11-08 12:08:55 +10001350 nv_call(disp->core, NV50_DISP_DAC_PWR + or, dpms_ctrl);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001351}
1352
1353static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001354nv50_dac_mode_fixup(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +02001355 const struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001356 struct drm_display_mode *adjusted_mode)
1357{
1358 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1359 struct nouveau_connector *nv_connector;
1360
1361 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1362 if (nv_connector && nv_connector->native_mode) {
1363 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
1364 int id = adjusted_mode->base.id;
1365 *adjusted_mode = *nv_connector->native_mode;
1366 adjusted_mode->base.id = id;
1367 }
1368 }
1369
1370 return true;
1371}
1372
1373static void
Ben Skeggse225f442012-11-21 14:40:21 +10001374nv50_dac_commit(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001375{
1376}
1377
1378static void
Ben Skeggse225f442012-11-21 14:40:21 +10001379nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001380 struct drm_display_mode *adjusted_mode)
1381{
Ben Skeggse225f442012-11-21 14:40:21 +10001382 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001383 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1384 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001385 u32 *push;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001386
Ben Skeggse225f442012-11-21 14:40:21 +10001387 nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001388
Ben Skeggs97b19b52012-11-16 11:21:37 +10001389 push = evo_wait(mast, 8);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001390 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +10001391 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001392 u32 syncs = 0x00000000;
1393
1394 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1395 syncs |= 0x00000001;
1396 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1397 syncs |= 0x00000002;
1398
1399 evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2);
1400 evo_data(push, 1 << nv_crtc->index);
1401 evo_data(push, syncs);
1402 } else {
1403 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1404 u32 syncs = 0x00000001;
1405
1406 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1407 syncs |= 0x00000008;
1408 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1409 syncs |= 0x00000010;
1410
1411 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1412 magic |= 0x00000001;
1413
1414 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1415 evo_data(push, syncs);
1416 evo_data(push, magic);
1417 evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1);
1418 evo_data(push, 1 << nv_crtc->index);
1419 }
1420
1421 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001422 }
1423
1424 nv_encoder->crtc = encoder->crtc;
1425}
1426
1427static void
Ben Skeggse225f442012-11-21 14:40:21 +10001428nv50_dac_disconnect(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001429{
1430 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001431 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs97b19b52012-11-16 11:21:37 +10001432 const int or = nv_encoder->or;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001433 u32 *push;
1434
1435 if (nv_encoder->crtc) {
Ben Skeggse225f442012-11-21 14:40:21 +10001436 nv50_crtc_prepare(nv_encoder->crtc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001437
Ben Skeggs97b19b52012-11-16 11:21:37 +10001438 push = evo_wait(mast, 4);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001439 if (push) {
Ben Skeggse225f442012-11-21 14:40:21 +10001440 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
Ben Skeggs97b19b52012-11-16 11:21:37 +10001441 evo_mthd(push, 0x0400 + (or * 0x080), 1);
1442 evo_data(push, 0x00000000);
1443 } else {
1444 evo_mthd(push, 0x0180 + (or * 0x020), 1);
1445 evo_data(push, 0x00000000);
1446 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001447 evo_kick(push, mast);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001448 }
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001449 }
Ben Skeggs97b19b52012-11-16 11:21:37 +10001450
1451 nv_encoder->crtc = NULL;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001452}
1453
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001454static enum drm_connector_status
Ben Skeggse225f442012-11-21 14:40:21 +10001455nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector)
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001456{
Ben Skeggse225f442012-11-21 14:40:21 +10001457 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs35b21d32012-11-08 12:08:55 +10001458 int ret, or = nouveau_encoder(encoder)->or;
Ben Skeggsd40ee482013-06-03 16:40:14 +10001459 u32 load = nouveau_drm(encoder->dev)->vbios.dactestval;
1460 if (load == 0)
1461 load = 340;
Ben Skeggsb6819932011-07-08 11:14:50 +10001462
Ben Skeggs35b21d32012-11-08 12:08:55 +10001463 ret = nv_exec(disp->core, NV50_DISP_DAC_LOAD + or, &load, sizeof(load));
Ben Skeggs4b31ebc2013-09-04 11:01:42 +10001464 if (ret || !load)
Ben Skeggs35b21d32012-11-08 12:08:55 +10001465 return connector_status_disconnected;
Ben Skeggsb6819932011-07-08 11:14:50 +10001466
Ben Skeggs35b21d32012-11-08 12:08:55 +10001467 return connector_status_connected;
Ben Skeggsb6d8e7e2011-07-07 09:51:29 +10001468}
1469
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001470static void
Ben Skeggse225f442012-11-21 14:40:21 +10001471nv50_dac_destroy(struct drm_encoder *encoder)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001472{
1473 drm_encoder_cleanup(encoder);
1474 kfree(encoder);
1475}
1476
Ben Skeggse225f442012-11-21 14:40:21 +10001477static const struct drm_encoder_helper_funcs nv50_dac_hfunc = {
1478 .dpms = nv50_dac_dpms,
1479 .mode_fixup = nv50_dac_mode_fixup,
1480 .prepare = nv50_dac_disconnect,
1481 .commit = nv50_dac_commit,
1482 .mode_set = nv50_dac_mode_set,
1483 .disable = nv50_dac_disconnect,
1484 .get_crtc = nv50_display_crtc_get,
1485 .detect = nv50_dac_detect
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001486};
1487
Ben Skeggse225f442012-11-21 14:40:21 +10001488static const struct drm_encoder_funcs nv50_dac_func = {
1489 .destroy = nv50_dac_destroy,
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001490};
1491
1492static int
Ben Skeggse225f442012-11-21 14:40:21 +10001493nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001494{
Ben Skeggs5ed50202013-02-11 20:15:03 +10001495 struct nouveau_drm *drm = nouveau_drm(connector->dev);
1496 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001497 struct nouveau_encoder *nv_encoder;
1498 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001499 int type = DRM_MODE_ENCODER_DAC;
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001500
1501 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1502 if (!nv_encoder)
1503 return -ENOMEM;
1504 nv_encoder->dcb = dcbe;
1505 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001506 nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001507
1508 encoder = to_drm_encoder(nv_encoder);
1509 encoder->possible_crtcs = dcbe->heads;
1510 encoder->possible_clones = 0;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001511 drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type);
Ben Skeggse225f442012-11-21 14:40:21 +10001512 drm_encoder_helper_add(encoder, &nv50_dac_hfunc);
Ben Skeggs8eaa9662011-07-06 15:25:47 +10001513
1514 drm_mode_connector_attach_encoder(connector, encoder);
1515 return 0;
1516}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001517
1518/******************************************************************************
Ben Skeggs78951d22011-11-11 18:13:13 +10001519 * Audio
1520 *****************************************************************************/
1521static void
Ben Skeggse225f442012-11-21 14:40:21 +10001522nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001523{
1524 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1525 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10001526 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001527
1528 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1529 if (!drm_detect_monitor_audio(nv_connector->edid))
1530 return;
1531
Ben Skeggs78951d22011-11-11 18:13:13 +10001532 drm_edid_to_eld(&nv_connector->base, nv_connector->edid);
Ben Skeggs78951d22011-11-11 18:13:13 +10001533
Ben Skeggs0a9e2b952012-11-08 14:03:56 +10001534 nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or,
1535 nv_connector->base.eld,
1536 nv_connector->base.eld[2] * 4);
Ben Skeggs78951d22011-11-11 18:13:13 +10001537}
1538
1539static void
Ben Skeggse225f442012-11-21 14:40:21 +10001540nv50_audio_disconnect(struct drm_encoder *encoder)
Ben Skeggs78951d22011-11-11 18:13:13 +10001541{
1542 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001543 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001544
Ben Skeggs0a9e2b952012-11-08 14:03:56 +10001545 nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or, NULL, 0);
Ben Skeggs78951d22011-11-11 18:13:13 +10001546}
1547
1548/******************************************************************************
1549 * HDMI
1550 *****************************************************************************/
1551static void
Ben Skeggse225f442012-11-21 14:40:21 +10001552nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode)
Ben Skeggs78951d22011-11-11 18:13:13 +10001553{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001554 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1555 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1556 struct nouveau_connector *nv_connector;
Ben Skeggse225f442012-11-21 14:40:21 +10001557 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs1c30cd02012-11-08 14:22:28 +10001558 const u32 moff = (nv_crtc->index << 3) | nv_encoder->or;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001559 u32 rekey = 56; /* binary driver, and tegra constant */
1560 u32 max_ac_packet;
1561
1562 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1563 if (!drm_detect_hdmi_monitor(nv_connector->edid))
1564 return;
1565
1566 max_ac_packet = mode->htotal - mode->hdisplay;
1567 max_ac_packet -= rekey;
1568 max_ac_packet -= 18; /* constant from tegra */
1569 max_ac_packet /= 32;
1570
Ben Skeggs1c30cd02012-11-08 14:22:28 +10001571 nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff,
1572 NV84_DISP_SOR_HDMI_PWR_STATE_ON |
1573 (max_ac_packet << 16) | rekey);
Ben Skeggs091e40c2011-11-11 20:46:00 +10001574
Ben Skeggse225f442012-11-21 14:40:21 +10001575 nv50_audio_mode_set(encoder, mode);
Ben Skeggs78951d22011-11-11 18:13:13 +10001576}
1577
1578static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001579nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc)
Ben Skeggs78951d22011-11-11 18:13:13 +10001580{
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001581 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse225f442012-11-21 14:40:21 +10001582 struct nv50_disp *disp = nv50_disp(encoder->dev);
Ben Skeggs1c30cd02012-11-08 14:22:28 +10001583 const u32 moff = (nv_crtc->index << 3) | nv_encoder->or;
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001584
Ben Skeggse225f442012-11-21 14:40:21 +10001585 nv50_audio_disconnect(encoder);
Ben Skeggs64d9cc02011-11-11 19:51:20 +10001586
Ben Skeggs1c30cd02012-11-08 14:22:28 +10001587 nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff, 0x00000000);
Ben Skeggs78951d22011-11-11 18:13:13 +10001588}
1589
1590/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10001591 * SOR
1592 *****************************************************************************/
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001593static void
Ben Skeggse225f442012-11-21 14:40:21 +10001594nv50_sor_dpms(struct drm_encoder *encoder, int mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001595{
1596 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1597 struct drm_device *dev = encoder->dev;
Ben Skeggse225f442012-11-21 14:40:21 +10001598 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001599 struct drm_encoder *partner;
Ben Skeggs48743222014-05-31 01:48:06 +10001600 u32 mthd;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001601
1602 nv_encoder->last_dpms = mode;
1603
1604 list_for_each_entry(partner, &dev->mode_config.encoder_list, head) {
1605 struct nouveau_encoder *nv_partner = nouveau_encoder(partner);
1606
1607 if (partner->encoder_type != DRM_MODE_ENCODER_TMDS)
1608 continue;
1609
1610 if (nv_partner != nv_encoder &&
Ben Skeggs26cfa812011-11-17 09:10:02 +10001611 nv_partner->dcb->or == nv_encoder->dcb->or) {
Ben Skeggs83fc0832011-07-05 13:08:40 +10001612 if (nv_partner->last_dpms == DRM_MODE_DPMS_ON)
1613 return;
1614 break;
1615 }
1616 }
1617
Ben Skeggs276e5262014-06-30 11:10:02 +10001618 mthd = (ffs(nv_encoder->dcb->heads) - 1) << 3;
1619 mthd |= (ffs(nv_encoder->dcb->sorconf.link) - 1) << 2;
Ben Skeggs48743222014-05-31 01:48:06 +10001620 mthd |= nv_encoder->or;
1621
1622 if (nv_encoder->dcb->type == DCB_OUTPUT_DP) {
1623 nv_call(disp->core, NV50_DISP_SOR_PWR | mthd, 1);
1624 mthd |= NV94_DISP_SOR_DP_PWR;
1625 } else {
1626 mthd |= NV50_DISP_SOR_PWR;
1627 }
1628
1629 nv_call(disp->core, mthd, (mode == DRM_MODE_DPMS_ON));
Ben Skeggs83fc0832011-07-05 13:08:40 +10001630}
1631
1632static bool
Ben Skeggse225f442012-11-21 14:40:21 +10001633nv50_sor_mode_fixup(struct drm_encoder *encoder,
Laurent Pincharte811f5a2012-07-17 17:56:50 +02001634 const struct drm_display_mode *mode,
Ben Skeggs83fc0832011-07-05 13:08:40 +10001635 struct drm_display_mode *adjusted_mode)
1636{
1637 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1638 struct nouveau_connector *nv_connector;
1639
1640 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1641 if (nv_connector && nv_connector->native_mode) {
1642 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
1643 int id = adjusted_mode->base.id;
1644 *adjusted_mode = *nv_connector->native_mode;
1645 adjusted_mode->base.id = id;
1646 }
1647 }
1648
1649 return true;
1650}
1651
1652static void
Ben Skeggse84a35a2014-06-05 10:59:55 +10001653nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data)
1654{
1655 struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev);
1656 u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push;
1657 if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) {
1658 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
1659 evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1);
1660 evo_data(push, (nv_encoder->ctrl = temp));
1661 } else {
1662 evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1);
1663 evo_data(push, (nv_encoder->ctrl = temp));
1664 }
1665 evo_kick(push, mast);
1666 }
1667}
1668
1669static void
Ben Skeggse225f442012-11-21 14:40:21 +10001670nv50_sor_disconnect(struct drm_encoder *encoder)
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001671{
1672 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001673 struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001674
1675 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1676 nv_encoder->crtc = NULL;
Ben Skeggse84a35a2014-06-05 10:59:55 +10001677
1678 if (nv_crtc) {
1679 nv50_crtc_prepare(&nv_crtc->base);
1680 nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0);
1681 nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc);
1682 }
Ben Skeggs4cbb0f82012-03-12 15:23:44 +10001683}
1684
1685static void
Ben Skeggse225f442012-11-21 14:40:21 +10001686nv50_sor_commit(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001687{
1688}
1689
1690static void
Ben Skeggse225f442012-11-21 14:40:21 +10001691nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode,
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001692 struct drm_display_mode *mode)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001693{
Ben Skeggse225f442012-11-21 14:40:21 +10001694 struct nv50_disp *disp = nv50_disp(encoder->dev);
1695 struct nv50_mast *mast = nv50_mast(encoder->dev);
Ben Skeggs78951d22011-11-11 18:13:13 +10001696 struct drm_device *dev = encoder->dev;
Ben Skeggs77145f12012-07-31 16:16:21 +10001697 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001698 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1699 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001700 struct nouveau_connector *nv_connector;
Ben Skeggs77145f12012-07-31 16:16:21 +10001701 struct nvbios *bios = &drm->vbios;
Ben Skeggse84a35a2014-06-05 10:59:55 +10001702 u32 lvds = 0, mask, ctrl;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001703 u8 owner = 1 << nv_crtc->index;
1704 u8 proto = 0xf;
1705 u8 depth = 0x0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001706
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001707 nv_connector = nouveau_encoder_connector_get(nv_encoder);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001708 nv_encoder->crtc = encoder->crtc;
1709
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001710 switch (nv_encoder->dcb->type) {
Ben Skeggscb75d972012-07-11 10:44:20 +10001711 case DCB_OUTPUT_TMDS:
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001712 if (nv_encoder->dcb->sorconf.link & 1) {
1713 if (mode->clock < 165000)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001714 proto = 0x1;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001715 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001716 proto = 0x5;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001717 } else {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001718 proto = 0x2;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001719 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001720
Ben Skeggse84a35a2014-06-05 10:59:55 +10001721 nv50_hdmi_mode_set(&nv_encoder->base.base, mode);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001722 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001723 case DCB_OUTPUT_LVDS:
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001724 proto = 0x0;
1725
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001726 if (bios->fp_no_ddc) {
1727 if (bios->fp.dual_link)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001728 lvds |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001729 if (bios->fp.if_is_24bit)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001730 lvds |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001731 } else {
Ben Skeggsbefb51e2011-11-18 10:23:59 +10001732 if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001733 if (((u8 *)nv_connector->edid)[121] == 2)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001734 lvds |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001735 } else
1736 if (mode->clock >= bios->fp.duallink_transition_clk) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001737 lvds |= 0x0100;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001738 }
1739
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001740 if (lvds & 0x0100) {
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001741 if (bios->fp.strapless_is_24bit & 2)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001742 lvds |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001743 } else {
1744 if (bios->fp.strapless_is_24bit & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001745 lvds |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001746 }
1747
1748 if (nv_connector->base.display_info.bpc == 8)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001749 lvds |= 0x0200;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001750 }
Ben Skeggs4a230fa2012-11-09 11:25:37 +10001751
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001752 nv_call(disp->core, NV50_DISP_SOR_LVDS_SCRIPT + nv_encoder->or, lvds);
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001753 break;
Ben Skeggscb75d972012-07-11 10:44:20 +10001754 case DCB_OUTPUT_DP:
Ben Skeggs3488c572012-03-12 11:42:20 +10001755 if (nv_connector->base.display_info.bpc == 6) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001756 nv_encoder->dp.datarate = mode->clock * 18 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001757 depth = 0x2;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10001758 } else
1759 if (nv_connector->base.display_info.bpc == 8) {
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001760 nv_encoder->dp.datarate = mode->clock * 24 / 8;
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001761 depth = 0x5;
Ben Skeggsbf2c8862012-11-21 14:49:54 +10001762 } else {
1763 nv_encoder->dp.datarate = mode->clock * 30 / 8;
1764 depth = 0x6;
Ben Skeggs3488c572012-03-12 11:42:20 +10001765 }
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001766
1767 if (nv_encoder->dcb->sorconf.link & 1)
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001768 proto = 0x8;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001769 else
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001770 proto = 0x9;
Ben Skeggs6e83fda2012-03-11 01:28:48 +10001771 break;
Ben Skeggs3b6d83d12011-07-08 12:52:14 +10001772 default:
1773 BUG_ON(1);
1774 break;
1775 }
Ben Skeggsff8ff502011-07-08 11:53:37 +10001776
Ben Skeggse84a35a2014-06-05 10:59:55 +10001777 nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001778
Ben Skeggse84a35a2014-06-05 10:59:55 +10001779 if (nv50_vers(mast) >= NVD0_DISP_CLASS) {
1780 u32 *push = evo_wait(mast, 3);
1781 if (push) {
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001782 u32 magic = 0x31ec6000 | (nv_crtc->index << 25);
1783 u32 syncs = 0x00000001;
1784
1785 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1786 syncs |= 0x00000008;
1787 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1788 syncs |= 0x00000010;
1789
1790 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1791 magic |= 0x00000001;
1792
1793 evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2);
1794 evo_data(push, syncs | (depth << 6));
1795 evo_data(push, magic);
Ben Skeggse84a35a2014-06-05 10:59:55 +10001796 evo_kick(push, mast);
Ben Skeggs419e8dc2012-11-16 11:40:34 +10001797 }
1798
Ben Skeggse84a35a2014-06-05 10:59:55 +10001799 ctrl = proto << 8;
1800 mask = 0x00000f00;
1801 } else {
1802 ctrl = (depth << 16) | (proto << 8);
1803 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1804 ctrl |= 0x00001000;
1805 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1806 ctrl |= 0x00002000;
1807 mask = 0x000f3f00;
Ben Skeggs83fc0832011-07-05 13:08:40 +10001808 }
1809
Ben Skeggse84a35a2014-06-05 10:59:55 +10001810 nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001811}
1812
1813static void
Ben Skeggse225f442012-11-21 14:40:21 +10001814nv50_sor_destroy(struct drm_encoder *encoder)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001815{
1816 drm_encoder_cleanup(encoder);
1817 kfree(encoder);
1818}
1819
Ben Skeggse225f442012-11-21 14:40:21 +10001820static const struct drm_encoder_helper_funcs nv50_sor_hfunc = {
1821 .dpms = nv50_sor_dpms,
1822 .mode_fixup = nv50_sor_mode_fixup,
Ben Skeggs5a885f02013-02-20 14:34:18 +10001823 .prepare = nv50_sor_disconnect,
Ben Skeggse225f442012-11-21 14:40:21 +10001824 .commit = nv50_sor_commit,
1825 .mode_set = nv50_sor_mode_set,
1826 .disable = nv50_sor_disconnect,
1827 .get_crtc = nv50_display_crtc_get,
Ben Skeggs83fc0832011-07-05 13:08:40 +10001828};
1829
Ben Skeggse225f442012-11-21 14:40:21 +10001830static const struct drm_encoder_funcs nv50_sor_func = {
1831 .destroy = nv50_sor_destroy,
Ben Skeggs83fc0832011-07-05 13:08:40 +10001832};
1833
1834static int
Ben Skeggse225f442012-11-21 14:40:21 +10001835nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe)
Ben Skeggs83fc0832011-07-05 13:08:40 +10001836{
Ben Skeggs5ed50202013-02-11 20:15:03 +10001837 struct nouveau_drm *drm = nouveau_drm(connector->dev);
1838 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001839 struct nouveau_encoder *nv_encoder;
1840 struct drm_encoder *encoder;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001841 int type;
1842
1843 switch (dcbe->type) {
1844 case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break;
1845 case DCB_OUTPUT_TMDS:
1846 case DCB_OUTPUT_DP:
1847 default:
1848 type = DRM_MODE_ENCODER_TMDS;
1849 break;
1850 }
Ben Skeggs83fc0832011-07-05 13:08:40 +10001851
1852 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
1853 if (!nv_encoder)
1854 return -ENOMEM;
1855 nv_encoder->dcb = dcbe;
1856 nv_encoder->or = ffs(dcbe->or) - 1;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001857 nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001858 nv_encoder->last_dpms = DRM_MODE_DPMS_OFF;
1859
1860 encoder = to_drm_encoder(nv_encoder);
1861 encoder->possible_crtcs = dcbe->heads;
1862 encoder->possible_clones = 0;
Ben Skeggs5ed50202013-02-11 20:15:03 +10001863 drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type);
Ben Skeggse225f442012-11-21 14:40:21 +10001864 drm_encoder_helper_add(encoder, &nv50_sor_hfunc);
Ben Skeggs83fc0832011-07-05 13:08:40 +10001865
1866 drm_mode_connector_attach_encoder(connector, encoder);
1867 return 0;
1868}
Ben Skeggs26f6d882011-07-04 16:25:18 +10001869
1870/******************************************************************************
Ben Skeggseb6313a2013-02-11 09:52:58 +10001871 * PIOR
1872 *****************************************************************************/
1873
1874static void
1875nv50_pior_dpms(struct drm_encoder *encoder, int mode)
1876{
1877 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1878 struct nv50_disp *disp = nv50_disp(encoder->dev);
1879 u32 mthd = (nv_encoder->dcb->type << 12) | nv_encoder->or;
1880 u32 ctrl = (mode == DRM_MODE_DPMS_ON);
1881 nv_call(disp->core, NV50_DISP_PIOR_PWR + mthd, ctrl);
1882}
1883
1884static bool
1885nv50_pior_mode_fixup(struct drm_encoder *encoder,
1886 const struct drm_display_mode *mode,
1887 struct drm_display_mode *adjusted_mode)
1888{
1889 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1890 struct nouveau_connector *nv_connector;
1891
1892 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1893 if (nv_connector && nv_connector->native_mode) {
1894 if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) {
1895 int id = adjusted_mode->base.id;
1896 *adjusted_mode = *nv_connector->native_mode;
1897 adjusted_mode->base.id = id;
1898 }
1899 }
1900
1901 adjusted_mode->clock *= 2;
1902 return true;
1903}
1904
1905static void
1906nv50_pior_commit(struct drm_encoder *encoder)
1907{
1908}
1909
1910static void
1911nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode,
1912 struct drm_display_mode *adjusted_mode)
1913{
1914 struct nv50_mast *mast = nv50_mast(encoder->dev);
1915 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1916 struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc);
1917 struct nouveau_connector *nv_connector;
1918 u8 owner = 1 << nv_crtc->index;
1919 u8 proto, depth;
1920 u32 *push;
1921
1922 nv_connector = nouveau_encoder_connector_get(nv_encoder);
1923 switch (nv_connector->base.display_info.bpc) {
1924 case 10: depth = 0x6; break;
1925 case 8: depth = 0x5; break;
1926 case 6: depth = 0x2; break;
1927 default: depth = 0x0; break;
1928 }
1929
1930 switch (nv_encoder->dcb->type) {
1931 case DCB_OUTPUT_TMDS:
1932 case DCB_OUTPUT_DP:
1933 proto = 0x0;
1934 break;
1935 default:
1936 BUG_ON(1);
1937 break;
1938 }
1939
1940 nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON);
1941
1942 push = evo_wait(mast, 8);
1943 if (push) {
1944 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
1945 u32 ctrl = (depth << 16) | (proto << 8) | owner;
1946 if (mode->flags & DRM_MODE_FLAG_NHSYNC)
1947 ctrl |= 0x00001000;
1948 if (mode->flags & DRM_MODE_FLAG_NVSYNC)
1949 ctrl |= 0x00002000;
1950 evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1);
1951 evo_data(push, ctrl);
1952 }
1953
1954 evo_kick(push, mast);
1955 }
1956
1957 nv_encoder->crtc = encoder->crtc;
1958}
1959
1960static void
1961nv50_pior_disconnect(struct drm_encoder *encoder)
1962{
1963 struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder);
1964 struct nv50_mast *mast = nv50_mast(encoder->dev);
1965 const int or = nv_encoder->or;
1966 u32 *push;
1967
1968 if (nv_encoder->crtc) {
1969 nv50_crtc_prepare(nv_encoder->crtc);
1970
1971 push = evo_wait(mast, 4);
1972 if (push) {
1973 if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) {
1974 evo_mthd(push, 0x0700 + (or * 0x040), 1);
1975 evo_data(push, 0x00000000);
1976 }
Ben Skeggseb6313a2013-02-11 09:52:58 +10001977 evo_kick(push, mast);
1978 }
1979 }
1980
1981 nv_encoder->crtc = NULL;
1982}
1983
1984static void
1985nv50_pior_destroy(struct drm_encoder *encoder)
1986{
1987 drm_encoder_cleanup(encoder);
1988 kfree(encoder);
1989}
1990
1991static const struct drm_encoder_helper_funcs nv50_pior_hfunc = {
1992 .dpms = nv50_pior_dpms,
1993 .mode_fixup = nv50_pior_mode_fixup,
1994 .prepare = nv50_pior_disconnect,
1995 .commit = nv50_pior_commit,
1996 .mode_set = nv50_pior_mode_set,
1997 .disable = nv50_pior_disconnect,
1998 .get_crtc = nv50_display_crtc_get,
1999};
2000
2001static const struct drm_encoder_funcs nv50_pior_func = {
2002 .destroy = nv50_pior_destroy,
2003};
2004
2005static int
2006nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe)
2007{
2008 struct nouveau_drm *drm = nouveau_drm(connector->dev);
2009 struct nouveau_i2c *i2c = nouveau_i2c(drm->device);
2010 struct nouveau_i2c_port *ddc = NULL;
2011 struct nouveau_encoder *nv_encoder;
2012 struct drm_encoder *encoder;
2013 int type;
2014
2015 switch (dcbe->type) {
2016 case DCB_OUTPUT_TMDS:
2017 ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTDDC(dcbe->extdev));
2018 type = DRM_MODE_ENCODER_TMDS;
2019 break;
2020 case DCB_OUTPUT_DP:
2021 ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTAUX(dcbe->extdev));
2022 type = DRM_MODE_ENCODER_TMDS;
2023 break;
2024 default:
2025 return -ENODEV;
2026 }
2027
2028 nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL);
2029 if (!nv_encoder)
2030 return -ENOMEM;
2031 nv_encoder->dcb = dcbe;
2032 nv_encoder->or = ffs(dcbe->or) - 1;
2033 nv_encoder->i2c = ddc;
2034
2035 encoder = to_drm_encoder(nv_encoder);
2036 encoder->possible_crtcs = dcbe->heads;
2037 encoder->possible_clones = 0;
2038 drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type);
2039 drm_encoder_helper_add(encoder, &nv50_pior_hfunc);
2040
2041 drm_mode_connector_attach_encoder(connector, encoder);
2042 return 0;
2043}
2044
2045/******************************************************************************
Ben Skeggsab0af552014-08-10 04:10:19 +10002046 * Framebuffer
2047 *****************************************************************************/
2048
Ben Skeggs8a423642014-08-10 04:10:19 +10002049struct nv50_fbdma {
2050 struct list_head head;
2051 u32 name;
2052};
2053
2054static void
2055nv50_fbdma_fini(struct drm_device *dev, struct nv50_fbdma *fbdma)
2056{
2057 struct nv50_disp *disp = nv50_disp(dev);
2058 struct nv50_mast *mast = nv50_mast(dev);
2059 struct nouveau_object *client = nv_pclass(disp->core, NV_CLIENT_CLASS);
2060 struct drm_crtc *crtc;
2061
2062 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2063 struct nv50_sync *sync = nv50_sync(crtc);
2064 nouveau_object_del(client, sync->base.base.handle, fbdma->name);
2065 }
2066
2067 nouveau_object_del(client, mast->base.base.handle, fbdma->name);
2068 list_del(&fbdma->head);
2069 kfree(fbdma);
2070}
2071
2072static int
2073nv50_fbdma_init(struct drm_device *dev, u32 name, u64 offset, u64 length, u8 kind)
2074{
2075 struct nouveau_drm *drm = nouveau_drm(dev);
2076 struct nv50_disp *disp = nv50_disp(dev);
2077 struct nv50_mast *mast = nv50_mast(dev);
2078 struct nouveau_object *client = nv_pclass(disp->core, NV_CLIENT_CLASS);
2079 struct nouveau_object *object;
2080 struct nv_dma_class args;
2081 struct nv50_fbdma *fbdma;
2082 struct drm_crtc *crtc;
2083 int ret;
2084
2085 list_for_each_entry(fbdma, &disp->fbdma, head) {
2086 if (fbdma->name == name)
2087 return 0;
2088 }
2089
2090 fbdma = kzalloc(sizeof(*fbdma), GFP_KERNEL);
2091 if (!fbdma)
2092 return -ENOMEM;
2093 list_add(&fbdma->head, &disp->fbdma);
2094 fbdma->name = name;
2095
2096 args.flags = NV_DMA_TARGET_VRAM | NV_DMA_ACCESS_RDWR;
2097 args.start = offset;
2098 args.limit = offset + length - 1;
2099 args.conf0 = kind;
2100
2101 if (nv_device(drm->device)->chipset < 0x80) {
2102 args.conf0 = NV50_DMA_CONF0_ENABLE;
2103 args.conf0 |= NV50_DMA_CONF0_PART_256;
2104 } else
2105 if (nv_device(drm->device)->chipset < 0xc0) {
2106 args.conf0 |= NV50_DMA_CONF0_ENABLE;
2107 args.conf0 |= NV50_DMA_CONF0_PART_256;
2108 } else
2109 if (nv_device(drm->device)->chipset < 0xd0) {
2110 args.conf0 |= NVC0_DMA_CONF0_ENABLE;
2111 } else {
2112 args.conf0 |= NVD0_DMA_CONF0_ENABLE;
2113 args.conf0 |= NVD0_DMA_CONF0_PAGE_LP;
2114 }
2115
2116 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2117 struct nv50_sync *sync = nv50_sync(crtc);
2118 ret = nouveau_object_new(client, sync->base.base.handle,
2119 fbdma->name, NV_DMA_IN_MEMORY_CLASS,
2120 &args, sizeof(args), &object);
2121 if (ret) {
2122 printk(KERN_ERR "fail %d %08x %d\n", nv50_head(crtc)->base.index, fbdma->name, ret);
2123 nv50_fbdma_fini(dev, fbdma);
2124 return ret;
2125 }
2126 }
2127
2128 ret = nouveau_object_new(client, mast->base.base.handle, fbdma->name,
2129 NV_DMA_IN_MEMORY_CLASS, &args, sizeof(args),
2130 &object);
2131 if (ret) {
2132 printk(KERN_ERR "fail %08x %d\n", fbdma->name, ret);
2133 nv50_fbdma_fini(dev, fbdma);
2134 return ret;
2135 }
2136
2137 return 0;
2138}
2139
Ben Skeggsab0af552014-08-10 04:10:19 +10002140static void
2141nv50_fb_dtor(struct drm_framebuffer *fb)
2142{
2143}
2144
2145static int
2146nv50_fb_ctor(struct drm_framebuffer *fb)
2147{
2148 struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb);
2149 struct nouveau_drm *drm = nouveau_drm(fb->dev);
2150 struct nouveau_bo *nvbo = nv_fb->nvbo;
Ben Skeggs8a423642014-08-10 04:10:19 +10002151 struct nv50_disp *disp = nv50_disp(fb->dev);
2152 struct nouveau_fb *pfb = nouveau_fb(drm->device);
2153 u8 kind = nouveau_bo_tile_layout(nvbo) >> 8;
2154 u8 tile = nvbo->tile_mode;
Ben Skeggsab0af552014-08-10 04:10:19 +10002155
2156 if (nvbo->tile_flags & NOUVEAU_GEM_TILE_NONCONTIG) {
2157 NV_ERROR(drm, "framebuffer requires contiguous bo\n");
2158 return -EINVAL;
2159 }
2160
Ben Skeggs8a423642014-08-10 04:10:19 +10002161 if (nv_device(drm->device)->chipset >= 0xc0)
2162 tile >>= 4; /* yep.. */
2163
Ben Skeggsab0af552014-08-10 04:10:19 +10002164 switch (fb->depth) {
2165 case 8: nv_fb->r_format = 0x1e00; break;
2166 case 15: nv_fb->r_format = 0xe900; break;
2167 case 16: nv_fb->r_format = 0xe800; break;
2168 case 24:
2169 case 32: nv_fb->r_format = 0xcf00; break;
2170 case 30: nv_fb->r_format = 0xd100; break;
2171 default:
2172 NV_ERROR(drm, "unknown depth %d\n", fb->depth);
2173 return -EINVAL;
2174 }
2175
Ben Skeggs8a423642014-08-10 04:10:19 +10002176 if (nv_mclass(disp->core) < NV84_DISP_CLASS) {
2177 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2178 (fb->pitches[0] | 0x00100000);
2179 nv_fb->r_format |= kind << 16;
2180 } else
2181 if (nv_mclass(disp->core) < NVD0_DISP_CLASS) {
2182 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2183 (fb->pitches[0] | 0x00100000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002184 } else {
Ben Skeggs8a423642014-08-10 04:10:19 +10002185 nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) :
2186 (fb->pitches[0] | 0x01000000);
Ben Skeggsab0af552014-08-10 04:10:19 +10002187 }
Ben Skeggs8a423642014-08-10 04:10:19 +10002188 nv_fb->r_handle = 0xffff0000 | kind;
Ben Skeggsab0af552014-08-10 04:10:19 +10002189
Ben Skeggs8a423642014-08-10 04:10:19 +10002190 return nv50_fbdma_init(fb->dev, nv_fb->r_handle, 0, pfb->ram->size, kind);
Ben Skeggsab0af552014-08-10 04:10:19 +10002191}
2192
2193/******************************************************************************
Ben Skeggs26f6d882011-07-04 16:25:18 +10002194 * Init
2195 *****************************************************************************/
Ben Skeggsab0af552014-08-10 04:10:19 +10002196
Ben Skeggs2a44e492011-11-09 11:36:33 +10002197void
Ben Skeggse225f442012-11-21 14:40:21 +10002198nv50_display_fini(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002199{
Ben Skeggs26f6d882011-07-04 16:25:18 +10002200}
2201
2202int
Ben Skeggse225f442012-11-21 14:40:21 +10002203nv50_display_init(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002204{
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002205 struct nv50_disp *disp = nv50_disp(dev);
2206 struct drm_crtc *crtc;
2207 u32 *push;
2208
2209 push = evo_wait(nv50_mast(dev), 32);
2210 if (!push)
2211 return -EBUSY;
2212
2213 list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) {
2214 struct nv50_sync *sync = nv50_sync(crtc);
2215 nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002216 }
2217
Ben Skeggs9f9bdaa2013-03-02 13:21:31 +10002218 evo_mthd(push, 0x0088, 1);
2219 evo_data(push, NvEvoSync);
2220 evo_kick(push, nv50_mast(dev));
2221 return 0;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002222}
2223
2224void
Ben Skeggse225f442012-11-21 14:40:21 +10002225nv50_display_destroy(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002226{
Ben Skeggse225f442012-11-21 14:40:21 +10002227 struct nv50_disp *disp = nv50_disp(dev);
Ben Skeggs8a423642014-08-10 04:10:19 +10002228 struct nv50_fbdma *fbdma, *fbtmp;
2229
2230 list_for_each_entry_safe(fbdma, fbtmp, &disp->fbdma, head) {
2231 nv50_fbdma_fini(dev, fbdma);
2232 }
Ben Skeggs26f6d882011-07-04 16:25:18 +10002233
Ben Skeggse225f442012-11-21 14:40:21 +10002234 nv50_dmac_destroy(disp->core, &disp->mast.base);
Ben Skeggsbdb8c212011-11-12 01:30:24 +10002235
Ben Skeggs816af2f2011-11-16 15:48:48 +10002236 nouveau_bo_unmap(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002237 if (disp->sync)
2238 nouveau_bo_unpin(disp->sync);
Ben Skeggs816af2f2011-11-16 15:48:48 +10002239 nouveau_bo_ref(NULL, &disp->sync);
Ben Skeggs51beb422011-07-05 10:33:08 +10002240
Ben Skeggs77145f12012-07-31 16:16:21 +10002241 nouveau_display(dev)->priv = NULL;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002242 kfree(disp);
2243}
2244
2245int
Ben Skeggse225f442012-11-21 14:40:21 +10002246nv50_display_create(struct drm_device *dev)
Ben Skeggs26f6d882011-07-04 16:25:18 +10002247{
Ben Skeggs77145f12012-07-31 16:16:21 +10002248 struct nouveau_device *device = nouveau_dev(dev);
2249 struct nouveau_drm *drm = nouveau_drm(dev);
Ben Skeggs77145f12012-07-31 16:16:21 +10002250 struct dcb_table *dcb = &drm->vbios.dcb;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002251 struct drm_connector *connector, *tmp;
Ben Skeggse225f442012-11-21 14:40:21 +10002252 struct nv50_disp *disp;
Ben Skeggscb75d972012-07-11 10:44:20 +10002253 struct dcb_output *dcbe;
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002254 int crtcs, ret, i;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002255
2256 disp = kzalloc(sizeof(*disp), GFP_KERNEL);
2257 if (!disp)
2258 return -ENOMEM;
Ben Skeggs8a423642014-08-10 04:10:19 +10002259 INIT_LIST_HEAD(&disp->fbdma);
Ben Skeggs77145f12012-07-31 16:16:21 +10002260
2261 nouveau_display(dev)->priv = disp;
Ben Skeggse225f442012-11-21 14:40:21 +10002262 nouveau_display(dev)->dtor = nv50_display_destroy;
2263 nouveau_display(dev)->init = nv50_display_init;
2264 nouveau_display(dev)->fini = nv50_display_fini;
Ben Skeggsab0af552014-08-10 04:10:19 +10002265 nouveau_display(dev)->fb_ctor = nv50_fb_ctor;
2266 nouveau_display(dev)->fb_dtor = nv50_fb_dtor;
Ben Skeggs2332b312014-01-22 12:58:12 +10002267 disp->core = nouveau_display(dev)->core;
Ben Skeggs26f6d882011-07-04 16:25:18 +10002268
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002269 /* small shared memory area we use for notifiers and semaphores */
2270 ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM,
2271 0, 0x0000, NULL, &disp->sync);
2272 if (!ret) {
2273 ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002274 if (!ret) {
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002275 ret = nouveau_bo_map(disp->sync);
Marcin Slusarz04c8c212012-11-25 23:04:23 +01002276 if (ret)
2277 nouveau_bo_unpin(disp->sync);
2278 }
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002279 if (ret)
2280 nouveau_bo_ref(NULL, &disp->sync);
2281 }
2282
2283 if (ret)
2284 goto out;
2285
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002286 /* allocate master evo channel */
Ben Skeggse225f442012-11-21 14:40:21 +10002287 ret = nv50_dmac_create(disp->core, NV50_DISP_MAST_CLASS, 0,
Ben Skeggsb5a794b2012-10-16 14:18:32 +10002288 &(struct nv50_display_mast_class) {
2289 .pushbuf = EVO_PUSH_HANDLE(MAST, 0),
2290 }, sizeof(struct nv50_display_mast_class),
2291 disp->sync->bo.offset, &disp->mast.base);
2292 if (ret)
2293 goto out;
2294
Ben Skeggs438d99e2011-07-05 16:48:06 +10002295 /* create crtc objects to represent the hw heads */
Ben Skeggs63718a02012-11-16 11:44:14 +10002296 if (nv_mclass(disp->core) >= NVD0_DISP_CLASS)
2297 crtcs = nv_rd32(device, 0x022448);
2298 else
2299 crtcs = 2;
2300
Ben Skeggs7c5f6a82012-03-04 16:25:59 +10002301 for (i = 0; i < crtcs; i++) {
Ben Skeggse225f442012-11-21 14:40:21 +10002302 ret = nv50_crtc_create(dev, disp->core, i);
Ben Skeggs438d99e2011-07-05 16:48:06 +10002303 if (ret)
2304 goto out;
2305 }
2306
Ben Skeggs83fc0832011-07-05 13:08:40 +10002307 /* create encoder/connector objects based on VBIOS DCB table */
2308 for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) {
2309 connector = nouveau_connector_create(dev, dcbe->connector);
2310 if (IS_ERR(connector))
2311 continue;
2312
Ben Skeggseb6313a2013-02-11 09:52:58 +10002313 if (dcbe->location == DCB_LOC_ON_CHIP) {
2314 switch (dcbe->type) {
2315 case DCB_OUTPUT_TMDS:
2316 case DCB_OUTPUT_LVDS:
2317 case DCB_OUTPUT_DP:
2318 ret = nv50_sor_create(connector, dcbe);
2319 break;
2320 case DCB_OUTPUT_ANALOG:
2321 ret = nv50_dac_create(connector, dcbe);
2322 break;
2323 default:
2324 ret = -ENODEV;
2325 break;
2326 }
2327 } else {
2328 ret = nv50_pior_create(connector, dcbe);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002329 }
2330
Ben Skeggseb6313a2013-02-11 09:52:58 +10002331 if (ret) {
2332 NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n",
2333 dcbe->location, dcbe->type,
2334 ffs(dcbe->or) - 1, ret);
Ben Skeggs94f54f52013-03-05 22:26:06 +10002335 ret = 0;
Ben Skeggs83fc0832011-07-05 13:08:40 +10002336 }
2337 }
2338
2339 /* cull any connectors we created that don't have an encoder */
2340 list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) {
2341 if (connector->encoder_ids[0])
2342 continue;
2343
Ben Skeggs77145f12012-07-31 16:16:21 +10002344 NV_WARN(drm, "%s has no encoders, removing\n",
Jani Nikula8c6c3612014-06-03 14:56:18 +03002345 connector->name);
Ben Skeggs83fc0832011-07-05 13:08:40 +10002346 connector->funcs->destroy(connector);
2347 }
2348
Ben Skeggs26f6d882011-07-04 16:25:18 +10002349out:
2350 if (ret)
Ben Skeggse225f442012-11-21 14:40:21 +10002351 nv50_display_destroy(dev);
Ben Skeggs26f6d882011-07-04 16:25:18 +10002352 return ret;
2353}