xref: /openbmc/linux/drivers/gpu/drm/nouveau/dispnv50/head917d.c (revision f801efb127ad02e2cc6ddb1bf1e30bfe001fb4fe)
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 
39*f801efb1SBen Skeggs 	PUSH_MTHD(push, NV917D, HEAD_SET_DITHER_CONTROL(i),
40*f801efb1SBen Skeggs 		  NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, ENABLE, asyh->dither.enable) |
41*f801efb1SBen Skeggs 		  NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, BITS, asyh->dither.bits) |
42*f801efb1SBen Skeggs 		  NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, MODE, asyh->dither.mode) |
43*f801efb1SBen Skeggs 		  NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, PHASE, 0));
442f819f2bSBen Skeggs 	return 0;
4509e1b78aSBen Skeggs }
4609e1b78aSBen Skeggs 
4793f7f054SBen Skeggs static int
48119608a7SBen Skeggs head917d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
49119608a7SBen Skeggs {
5093f7f054SBen Skeggs 	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
5193f7f054SBen Skeggs 	const int i = head->base.index;
52119608a7SBen Skeggs 	u32 bounds = 0;
5393f7f054SBen Skeggs 	int ret;
54119608a7SBen Skeggs 
55119608a7SBen Skeggs 	if (asyh->base.cpp) {
56119608a7SBen Skeggs 		switch (asyh->base.cpp) {
572aa934caSBen Skeggs 		case 8: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_64); break;
582aa934caSBen Skeggs 		case 4: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_32); break;
592aa934caSBen Skeggs 		case 2: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_16); break;
602aa934caSBen Skeggs 		case 1: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_8); break;
61119608a7SBen Skeggs 		default:
62119608a7SBen Skeggs 			WARN_ON(1);
63119608a7SBen Skeggs 			break;
64119608a7SBen Skeggs 		}
652aa934caSBen Skeggs 		bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, USABLE, TRUE);
662aa934caSBen Skeggs 		bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, BASE_LUT, USAGE_1025);
67119608a7SBen Skeggs 	}
68119608a7SBen Skeggs 
6993f7f054SBen Skeggs 	if ((ret = PUSH_WAIT(push, 2)))
7093f7f054SBen Skeggs 		return ret;
7193f7f054SBen Skeggs 
722aa934caSBen Skeggs 	PUSH_MTHD(push, NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS(i), bounds);
7393f7f054SBen Skeggs 	return 0;
74119608a7SBen Skeggs }
75119608a7SBen Skeggs 
76facaed62SBen Skeggs int
7701d380abSBen Skeggs head917d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw,
7801d380abSBen Skeggs 		     struct nv50_head_atom *asyh)
7901d380abSBen Skeggs {
8001d380abSBen Skeggs 	switch (asyw->state.fb->width) {
81ed0b86a9SBen Skeggs 	case  32: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W32_H32; break;
82ed0b86a9SBen Skeggs 	case  64: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W64_H64; break;
83ed0b86a9SBen Skeggs 	case 128: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W128_H128; break;
84ed0b86a9SBen Skeggs 	case 256: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W256_H256; break;
8501d380abSBen Skeggs 	default:
8601d380abSBen Skeggs 		return -EINVAL;
8701d380abSBen Skeggs 	}
8801d380abSBen Skeggs 	return 0;
8901d380abSBen Skeggs }
9001d380abSBen Skeggs 
9109e1b78aSBen Skeggs const struct nv50_head_func
9209e1b78aSBen Skeggs head917d = {
9309e1b78aSBen Skeggs 	.view = head907d_view,
9409e1b78aSBen Skeggs 	.mode = head907d_mode,
95119608a7SBen Skeggs 	.olut = head907d_olut,
9613199270SIlia Mirkin 	.olut_size = 1024,
97119608a7SBen Skeggs 	.olut_set = head907d_olut_set,
98119608a7SBen Skeggs 	.olut_clr = head907d_olut_clr,
9909e1b78aSBen Skeggs 	.core_calc = head507d_core_calc,
10009e1b78aSBen Skeggs 	.core_set = head907d_core_set,
10109e1b78aSBen Skeggs 	.core_clr = head907d_core_clr,
10201d380abSBen Skeggs 	.curs_layout = head917d_curs_layout,
10301d380abSBen Skeggs 	.curs_format = head507d_curs_format,
10409e1b78aSBen Skeggs 	.curs_set = head907d_curs_set,
10509e1b78aSBen Skeggs 	.curs_clr = head907d_curs_clr,
106119608a7SBen Skeggs 	.base = head917d_base,
10709e1b78aSBen Skeggs 	.ovly = head907d_ovly,
10809e1b78aSBen Skeggs 	.dither = head917d_dither,
10909e1b78aSBen Skeggs 	.procamp = head907d_procamp,
11009e1b78aSBen Skeggs 	.or = head907d_or,
11109e1b78aSBen Skeggs };
112