xref: /openbmc/linux/drivers/gpu/drm/nouveau/dispnv50/head917d.c (revision 2aa934ca04bc93e7cf5133cb44a751be13b9df9e)
109e1b78aSBen Skeggs /*
209e1b78aSBen Skeggs  * Copyright 2018 Red Hat Inc.
309e1b78aSBen Skeggs  *
409e1b78aSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
509e1b78aSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
609e1b78aSBen Skeggs  * to deal in the Software without restriction, including without limitation
709e1b78aSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
809e1b78aSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
909e1b78aSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
1009e1b78aSBen Skeggs  *
1109e1b78aSBen Skeggs  * The above copyright notice and this permission notice shall be included in
1209e1b78aSBen Skeggs  * all copies or substantial portions of the Software.
1309e1b78aSBen Skeggs  *
1409e1b78aSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1509e1b78aSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1609e1b78aSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1709e1b78aSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1809e1b78aSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1909e1b78aSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2009e1b78aSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
2109e1b78aSBen Skeggs  */
2209e1b78aSBen Skeggs #include "head.h"
2309e1b78aSBen Skeggs #include "core.h"
2409e1b78aSBen Skeggs 
2593f7f054SBen Skeggs #include <nvif/push507c.h>
2693f7f054SBen Skeggs 
27ed0b86a9SBen Skeggs #include <nvhw/class/cl917d.h>
28ed0b86a9SBen Skeggs 
292f819f2bSBen Skeggs static int
3009e1b78aSBen Skeggs head917d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
3109e1b78aSBen Skeggs {
322f819f2bSBen Skeggs 	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
332f819f2bSBen Skeggs 	const int i = head->base.index;
342f819f2bSBen Skeggs 	int ret;
352f819f2bSBen Skeggs 
362f819f2bSBen Skeggs 	if ((ret = PUSH_WAIT(push, 2)))
372f819f2bSBen Skeggs 		return ret;
382f819f2bSBen Skeggs 
392f819f2bSBen Skeggs 	PUSH_NVSQ(push, NV917D, 0x04a0 + (i * 0x300), asyh->dither.mode << 3 |
4009e1b78aSBen Skeggs 						      asyh->dither.bits << 1 |
4109e1b78aSBen Skeggs 						      asyh->dither.enable);
422f819f2bSBen Skeggs 	return 0;
4309e1b78aSBen Skeggs }
4409e1b78aSBen Skeggs 
4593f7f054SBen Skeggs static int
46119608a7SBen Skeggs head917d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
47119608a7SBen Skeggs {
4893f7f054SBen Skeggs 	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
4993f7f054SBen Skeggs 	const int i = head->base.index;
50119608a7SBen Skeggs 	u32 bounds = 0;
5193f7f054SBen Skeggs 	int ret;
52119608a7SBen Skeggs 
53119608a7SBen Skeggs 	if (asyh->base.cpp) {
54119608a7SBen Skeggs 		switch (asyh->base.cpp) {
55*2aa934caSBen Skeggs 		case 8: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_64); break;
56*2aa934caSBen Skeggs 		case 4: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_32); break;
57*2aa934caSBen Skeggs 		case 2: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_16); break;
58*2aa934caSBen Skeggs 		case 1: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_8); break;
59119608a7SBen Skeggs 		default:
60119608a7SBen Skeggs 			WARN_ON(1);
61119608a7SBen Skeggs 			break;
62119608a7SBen Skeggs 		}
63*2aa934caSBen Skeggs 		bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, USABLE, TRUE);
64*2aa934caSBen Skeggs 		bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, BASE_LUT, USAGE_1025);
65119608a7SBen Skeggs 	}
66119608a7SBen Skeggs 
6793f7f054SBen Skeggs 	if ((ret = PUSH_WAIT(push, 2)))
6893f7f054SBen Skeggs 		return ret;
6993f7f054SBen Skeggs 
70*2aa934caSBen Skeggs 	PUSH_MTHD(push, NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS(i), bounds);
7193f7f054SBen Skeggs 	return 0;
72119608a7SBen Skeggs }
73119608a7SBen Skeggs 
74facaed62SBen Skeggs int
7501d380abSBen Skeggs head917d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw,
7601d380abSBen Skeggs 		     struct nv50_head_atom *asyh)
7701d380abSBen Skeggs {
7801d380abSBen Skeggs 	switch (asyw->state.fb->width) {
79ed0b86a9SBen Skeggs 	case  32: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W32_H32; break;
80ed0b86a9SBen Skeggs 	case  64: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W64_H64; break;
81ed0b86a9SBen Skeggs 	case 128: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W128_H128; break;
82ed0b86a9SBen Skeggs 	case 256: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W256_H256; break;
8301d380abSBen Skeggs 	default:
8401d380abSBen Skeggs 		return -EINVAL;
8501d380abSBen Skeggs 	}
8601d380abSBen Skeggs 	return 0;
8701d380abSBen Skeggs }
8801d380abSBen Skeggs 
8909e1b78aSBen Skeggs const struct nv50_head_func
9009e1b78aSBen Skeggs head917d = {
9109e1b78aSBen Skeggs 	.view = head907d_view,
9209e1b78aSBen Skeggs 	.mode = head907d_mode,
93119608a7SBen Skeggs 	.olut = head907d_olut,
9413199270SIlia Mirkin 	.olut_size = 1024,
95119608a7SBen Skeggs 	.olut_set = head907d_olut_set,
96119608a7SBen Skeggs 	.olut_clr = head907d_olut_clr,
9709e1b78aSBen Skeggs 	.core_calc = head507d_core_calc,
9809e1b78aSBen Skeggs 	.core_set = head907d_core_set,
9909e1b78aSBen Skeggs 	.core_clr = head907d_core_clr,
10001d380abSBen Skeggs 	.curs_layout = head917d_curs_layout,
10101d380abSBen Skeggs 	.curs_format = head507d_curs_format,
10209e1b78aSBen Skeggs 	.curs_set = head907d_curs_set,
10309e1b78aSBen Skeggs 	.curs_clr = head907d_curs_clr,
104119608a7SBen Skeggs 	.base = head917d_base,
10509e1b78aSBen Skeggs 	.ovly = head907d_ovly,
10609e1b78aSBen Skeggs 	.dither = head917d_dither,
10709e1b78aSBen Skeggs 	.procamp = head907d_procamp,
10809e1b78aSBen Skeggs 	.or = head907d_or,
10909e1b78aSBen Skeggs };
110