162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * Copyright 2018 Red Hat Inc.
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
562306a36Sopenharmony_ci * copy of this software and associated documentation files (the "Software"),
662306a36Sopenharmony_ci * to deal in the Software without restriction, including without limitation
762306a36Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense,
862306a36Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the
962306a36Sopenharmony_ci * Software is furnished to do so, subject to the following conditions:
1062306a36Sopenharmony_ci *
1162306a36Sopenharmony_ci * The above copyright notice and this permission notice shall be included in
1262306a36Sopenharmony_ci * all copies or substantial portions of the Software.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1562306a36Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1662306a36Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
1762306a36Sopenharmony_ci * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1862306a36Sopenharmony_ci * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1962306a36Sopenharmony_ci * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2062306a36Sopenharmony_ci * OTHER DEALINGS IN THE SOFTWARE.
2162306a36Sopenharmony_ci */
2262306a36Sopenharmony_ci#include "head.h"
2362306a36Sopenharmony_ci#include "core.h"
2462306a36Sopenharmony_ci
2562306a36Sopenharmony_ci#include "nvif/push.h"
2662306a36Sopenharmony_ci#include <nvif/push507c.h>
2762306a36Sopenharmony_ci
2862306a36Sopenharmony_ci#include <nvhw/class/cl917d.h>
2962306a36Sopenharmony_ci
3062306a36Sopenharmony_cistatic int
3162306a36Sopenharmony_cihead917d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
3262306a36Sopenharmony_ci{
3362306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
3462306a36Sopenharmony_ci	const int i = head->base.index;
3562306a36Sopenharmony_ci	int ret;
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 2)))
3862306a36Sopenharmony_ci		return ret;
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci	PUSH_MTHD(push, NV917D, HEAD_SET_DITHER_CONTROL(i),
4162306a36Sopenharmony_ci		  NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, ENABLE, asyh->dither.enable) |
4262306a36Sopenharmony_ci		  NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, BITS, asyh->dither.bits) |
4362306a36Sopenharmony_ci		  NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, MODE, asyh->dither.mode) |
4462306a36Sopenharmony_ci		  NVVAL(NV917D, HEAD_SET_DITHER_CONTROL, PHASE, 0));
4562306a36Sopenharmony_ci	return 0;
4662306a36Sopenharmony_ci}
4762306a36Sopenharmony_ci
4862306a36Sopenharmony_cistatic int
4962306a36Sopenharmony_cihead917d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
5062306a36Sopenharmony_ci{
5162306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
5262306a36Sopenharmony_ci	const int i = head->base.index;
5362306a36Sopenharmony_ci	u32 bounds = 0;
5462306a36Sopenharmony_ci	int ret;
5562306a36Sopenharmony_ci
5662306a36Sopenharmony_ci	if (asyh->base.cpp) {
5762306a36Sopenharmony_ci		switch (asyh->base.cpp) {
5862306a36Sopenharmony_ci		case 8: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_64); break;
5962306a36Sopenharmony_ci		case 4: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_32); break;
6062306a36Sopenharmony_ci		case 2: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_16); break;
6162306a36Sopenharmony_ci		case 1: bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_8); break;
6262306a36Sopenharmony_ci		default:
6362306a36Sopenharmony_ci			WARN_ON(1);
6462306a36Sopenharmony_ci			break;
6562306a36Sopenharmony_ci		}
6662306a36Sopenharmony_ci		bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, USABLE, TRUE);
6762306a36Sopenharmony_ci		bounds |= NVDEF(NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, BASE_LUT, USAGE_1025);
6862306a36Sopenharmony_ci	}
6962306a36Sopenharmony_ci
7062306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 2)))
7162306a36Sopenharmony_ci		return ret;
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ci	PUSH_MTHD(push, NV917D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS(i), bounds);
7462306a36Sopenharmony_ci	return 0;
7562306a36Sopenharmony_ci}
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cistatic int
7862306a36Sopenharmony_cihead917d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
7962306a36Sopenharmony_ci{
8062306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
8162306a36Sopenharmony_ci	const int i = head->base.index;
8262306a36Sopenharmony_ci	int ret;
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	ret = PUSH_WAIT(push, 5);
8562306a36Sopenharmony_ci	if (ret)
8662306a36Sopenharmony_ci		return ret;
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci	PUSH_MTHD(push, NV917D, HEAD_SET_CONTROL_CURSOR(i),
8962306a36Sopenharmony_ci		  NVDEF(NV917D, HEAD_SET_CONTROL_CURSOR, ENABLE, ENABLE) |
9062306a36Sopenharmony_ci		  NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, FORMAT, asyh->curs.format) |
9162306a36Sopenharmony_ci		  NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, SIZE, asyh->curs.layout) |
9262306a36Sopenharmony_ci		  NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_X, 0) |
9362306a36Sopenharmony_ci		  NVVAL(NV917D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_Y, 0) |
9462306a36Sopenharmony_ci		  NVDEF(NV917D, HEAD_SET_CONTROL_CURSOR, COMPOSITION, ALPHA_BLEND),
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci				HEAD_SET_OFFSET_CURSOR(i), asyh->curs.offset >> 8);
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci	PUSH_MTHD(push, NV917D, HEAD_SET_CONTEXT_DMA_CURSOR(i), asyh->curs.handle);
9962306a36Sopenharmony_ci	return 0;
10062306a36Sopenharmony_ci}
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ciint
10362306a36Sopenharmony_cihead917d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw,
10462306a36Sopenharmony_ci		     struct nv50_head_atom *asyh)
10562306a36Sopenharmony_ci{
10662306a36Sopenharmony_ci	switch (asyw->state.fb->width) {
10762306a36Sopenharmony_ci	case  32: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W32_H32; break;
10862306a36Sopenharmony_ci	case  64: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W64_H64; break;
10962306a36Sopenharmony_ci	case 128: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W128_H128; break;
11062306a36Sopenharmony_ci	case 256: asyh->curs.layout = NV917D_HEAD_SET_CONTROL_CURSOR_SIZE_W256_H256; break;
11162306a36Sopenharmony_ci	default:
11262306a36Sopenharmony_ci		return -EINVAL;
11362306a36Sopenharmony_ci	}
11462306a36Sopenharmony_ci	return 0;
11562306a36Sopenharmony_ci}
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ciconst struct nv50_head_func
11862306a36Sopenharmony_cihead917d = {
11962306a36Sopenharmony_ci	.view = head907d_view,
12062306a36Sopenharmony_ci	.mode = head907d_mode,
12162306a36Sopenharmony_ci	.olut = head907d_olut,
12262306a36Sopenharmony_ci	.ilut_check = head907d_ilut_check,
12362306a36Sopenharmony_ci	.olut_size = 1024,
12462306a36Sopenharmony_ci	.olut_set = head907d_olut_set,
12562306a36Sopenharmony_ci	.olut_clr = head907d_olut_clr,
12662306a36Sopenharmony_ci	.core_calc = head507d_core_calc,
12762306a36Sopenharmony_ci	.core_set = head907d_core_set,
12862306a36Sopenharmony_ci	.core_clr = head907d_core_clr,
12962306a36Sopenharmony_ci	.curs_layout = head917d_curs_layout,
13062306a36Sopenharmony_ci	.curs_format = head507d_curs_format,
13162306a36Sopenharmony_ci	.curs_set = head917d_curs_set,
13262306a36Sopenharmony_ci	.curs_clr = head907d_curs_clr,
13362306a36Sopenharmony_ci	.base = head917d_base,
13462306a36Sopenharmony_ci	.ovly = head907d_ovly,
13562306a36Sopenharmony_ci	.dither = head917d_dither,
13662306a36Sopenharmony_ci	.procamp = head907d_procamp,
13762306a36Sopenharmony_ci	.or = head907d_or,
13862306a36Sopenharmony_ci};
139