head507d.c 9.3 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
/*
 * Copyright 2018 Red Hat Inc.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
#include "head.h"
#include "core.h"

25
void
26 27 28 29 30
head507d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 *push;
	if ((push = evo_wait(core, 2))) {
31 32 33
		evo_mthd(push, 0x08a8 + (head->base.index * 0x400), 1);
		evo_data(push, asyh->procamp.sat.sin << 20 |
			       asyh->procamp.sat.cos << 8);
34 35 36 37
		evo_kick(push, core);
	}
}

38
void
39 40 41 42 43
head507d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 *push;
	if ((push = evo_wait(core, 2))) {
44 45 46 47
		evo_mthd(push, 0x08a0 + (head->base.index * 0x0400), 1);
		evo_data(push, asyh->dither.mode << 3 |
			       asyh->dither.bits << 1 |
			       asyh->dither.enable);
48 49 50 51
		evo_kick(push, core);
	}
}

52
void
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
head507d_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 bounds = 0;
	u32 *push;

	if (asyh->ovly.cpp) {
		switch (asyh->ovly.cpp) {
		case 4: bounds |= 0x00000300; break;
		case 2: bounds |= 0x00000100; break;
		default:
			WARN_ON(1);
			break;
		}
		bounds |= 0x00000001;
68 69
	} else {
		bounds |= 0x00000100;
70 71 72
	}

	if ((push = evo_wait(core, 2))) {
73
		evo_mthd(push, 0x0904 + head->base.index * 0x400, 1);
74 75 76 77 78
		evo_data(push, bounds);
		evo_kick(push, core);
	}
}

79
void
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
head507d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 bounds = 0;
	u32 *push;

	if (asyh->base.cpp) {
		switch (asyh->base.cpp) {
		case 8: bounds |= 0x00000500; break;
		case 4: bounds |= 0x00000300; break;
		case 2: bounds |= 0x00000100; break;
		case 1: bounds |= 0x00000000; break;
		default:
			WARN_ON(1);
			break;
		}
		bounds |= 0x00000001;
	}

	if ((push = evo_wait(core, 2))) {
100
		evo_mthd(push, 0x0900 + head->base.index * 0x400, 1);
101 102 103 104 105 106 107 108 109 110
		evo_data(push, bounds);
		evo_kick(push, core);
	}
}

static void
head507d_curs_clr(struct nv50_head *head)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 *push;
111 112 113
	if ((push = evo_wait(core, 2))) {
		evo_mthd(push, 0x0880 + head->base.index * 0x400, 1);
		evo_data(push, 0x05000000);
114 115 116 117 118 119 120 121 122
		evo_kick(push, core);
	}
}

static void
head507d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 *push;
123 124 125 126 127
	if ((push = evo_wait(core, 3))) {
		evo_mthd(push, 0x0880 + head->base.index * 0x400, 2);
		evo_data(push, 0x80000000 | asyh->curs.layout << 26 |
					    asyh->curs.format << 24);
		evo_data(push, asyh->curs.offset >> 8);
128 129 130 131
		evo_kick(push, core);
	}
}

132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
int
head507d_curs_format(struct nv50_head *head, struct nv50_wndw_atom *asyw,
		     struct nv50_head_atom *asyh)
{
	switch (asyw->image.format) {
	case 0xcf: asyh->curs.format = 1; break;
	default:
		WARN_ON(1);
		return -EINVAL;
	}
	return 0;
}

int
head507d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw,
		     struct nv50_head_atom *asyh)
{
	switch (asyw->image.w) {
	case 32: asyh->curs.layout = 0; break;
	case 64: asyh->curs.layout = 1; break;
	default:
		return -EINVAL;
	}
	return 0;
}

158
void
159 160 161 162 163
head507d_core_clr(struct nv50_head *head)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 *push;
	if ((push = evo_wait(core, 2))) {
164
		evo_mthd(push, 0x0874 + head->base.index * 0x400, 1);
165 166 167 168 169 170 171 172 173 174 175
		evo_data(push, 0x00000000);
		evo_kick(push, core);
	}
}

static void
head507d_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 *push;
	if ((push = evo_wait(core, 9))) {
176 177 178 179 180
		evo_mthd(push, 0x0860 + head->base.index * 0x400, 1);
		evo_data(push, asyh->core.offset >> 8);
		evo_mthd(push, 0x0868 + head->base.index * 0x400, 4);
		evo_data(push, asyh->core.h << 16 | asyh->core.w);
		evo_data(push, asyh->core.layout << 20 |
181 182 183
			       (asyh->core.pitch >> 8) << 8 |
			       asyh->core.blocks << 8 |
			       asyh->core.blockh);
184 185 186 187 188
		evo_data(push, asyh->core.kind << 16 |
			       asyh->core.format << 8);
		evo_data(push, asyh->core.handle);
		evo_mthd(push, 0x08c0 + head->base.index * 0x400, 1);
		evo_data(push, asyh->core.y << 16 | asyh->core.x);
189
		evo_kick(push, core);
190 191 192 193 194 195

		/* EVO will complain with INVALID_STATE if we have an
		 * active cursor and (re)specify HeadSetContextDmaIso
		 * without also updating HeadSetOffsetCursor.
		 */
		asyh->set.curs = asyh->curs.visible;
196
		asyh->set.olut = asyh->olut.handle != 0;
197 198 199 200 201 202 203 204 205 206 207 208 209
	}
}

void
head507d_core_calc(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	struct nv50_disp *disp = nv50_disp(head->base.base.dev);
	if ((asyh->core.visible = (asyh->base.cpp != 0))) {
		asyh->core.x = asyh->base.x;
		asyh->core.y = asyh->base.y;
		asyh->core.w = asyh->base.w;
		asyh->core.h = asyh->base.h;
	} else
210 211
	if ((asyh->core.visible = (asyh->ovly.cpp != 0)) ||
	    (asyh->core.visible = asyh->curs.visible)) {
212 213 214 215 216 217 218 219 220
		/*XXX: We need to either find some way of having the
		 *     primary base layer appear black, while still
		 *     being able to display the other layers, or we
		 *     need to allocate a dummy black surface here.
		 */
		asyh->core.x = 0;
		asyh->core.y = 0;
		asyh->core.w = asyh->state.mode.hdisplay;
		asyh->core.h = asyh->state.mode.vdisplay;
221
	}
222 223 224 225 226
	asyh->core.handle = disp->core->chan.vram.handle;
	asyh->core.offset = 0;
	asyh->core.format = 0xcf;
	asyh->core.kind = 0;
	asyh->core.layout = 1;
227 228
	asyh->core.blockh = 0;
	asyh->core.blocks = 0;
229
	asyh->core.pitch = ALIGN(asyh->core.w, 64) * 4;
230 231 232
}

static void
233
head507d_olut_clr(struct nv50_head *head)
234 235 236
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 *push;
237 238
	if ((push = evo_wait(core, 2))) {
		evo_mthd(push, 0x0840 + (head->base.index * 0x400), 1);
239
		evo_data(push, 0x00000000);
240 241 242 243 244
		evo_kick(push, core);
	}
}

static void
245
head507d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
246 247 248
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 *push;
249 250
	if ((push = evo_wait(core, 3))) {
		evo_mthd(push, 0x0840 + (head->base.index * 0x400), 2);
251 252
		evo_data(push, 0x80000000 | asyh->olut.mode << 30);
		evo_data(push, asyh->olut.offset >> 8);
253 254 255 256
		evo_kick(push, core);
	}
}

257 258 259 260 261 262 263 264 265
void
head507d_olut(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	if (asyh->base.cpp == 1)
		asyh->olut.mode = 0;
	else
		asyh->olut.mode = 1;
}

266
void
267 268 269 270 271
head507d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	struct nv50_head_mode *m = &asyh->mode;
	u32 *push;
272 273 274 275 276 277 278 279 280 281 282 283 284 285
	if ((push = evo_wait(core, 13))) {
		evo_mthd(push, 0x0804 + (head->base.index * 0x400), 2);
		evo_data(push, 0x00800000 | m->clock);
		evo_data(push, m->interlace ? 0x00000002 : 0x00000000);
		evo_mthd(push, 0x0810 + (head->base.index * 0x400), 7);
		evo_data(push, 0x00000000);
		evo_data(push, m->v.active  << 16 | m->h.active );
		evo_data(push, m->v.synce   << 16 | m->h.synce  );
		evo_data(push, m->v.blanke  << 16 | m->h.blanke );
		evo_data(push, m->v.blanks  << 16 | m->h.blanks );
		evo_data(push, m->v.blank2e << 16 | m->v.blank2s);
		evo_data(push, asyh->mode.v.blankus);
		evo_mthd(push, 0x082c + (head->base.index * 0x400), 1);
		evo_data(push, 0x00000000);
286 287 288 289
		evo_kick(push, core);
	}
}

290
void
291 292 293 294
head507d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
{
	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
	u32 *push;
295 296 297 298 299 300 301 302
	if ((push = evo_wait(core, 7))) {
		evo_mthd(push, 0x08a4 + (head->base.index * 0x400), 1);
		evo_data(push, 0x00000000);
		evo_mthd(push, 0x08c8 + (head->base.index * 0x400), 1);
		evo_data(push, asyh->view.iH << 16 | asyh->view.iW);
		evo_mthd(push, 0x08d8 + (head->base.index * 0x400), 2);
		evo_data(push, asyh->view.oH << 16 | asyh->view.oW);
		evo_data(push, asyh->view.oH << 16 | asyh->view.oW);
303 304 305 306 307 308 309 310
		evo_kick(push, core);
	}
}

const struct nv50_head_func
head507d = {
	.view = head507d_view,
	.mode = head507d_mode,
311 312 313
	.olut = head507d_olut,
	.olut_set = head507d_olut_set,
	.olut_clr = head507d_olut_clr,
314
	.core_calc = head507d_core_calc,
315 316
	.core_set = head507d_core_set,
	.core_clr = head507d_core_clr,
317 318
	.curs_layout = head507d_curs_layout,
	.curs_format = head507d_curs_format,
319 320 321 322 323 324 325
	.curs_set = head507d_curs_set,
	.curs_clr = head507d_curs_clr,
	.base = head507d_base,
	.ovly = head507d_ovly,
	.dither = head507d_dither,
	.procamp = head507d_procamp,
};