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 <drm/drm_connector.h>
2362306a36Sopenharmony_ci#include <drm/drm_mode_config.h>
2462306a36Sopenharmony_ci#include <drm/drm_vblank.h>
2562306a36Sopenharmony_ci#include "nouveau_drv.h"
2662306a36Sopenharmony_ci#include "nouveau_bios.h"
2762306a36Sopenharmony_ci#include "nouveau_connector.h"
2862306a36Sopenharmony_ci#include "head.h"
2962306a36Sopenharmony_ci#include "core.h"
3062306a36Sopenharmony_ci#include "crc.h"
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci#include <nvif/push507c.h>
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ci#include <nvhw/class/cl907d.h>
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciint
3762306a36Sopenharmony_cihead907d_or(struct nv50_head *head, struct nv50_head_atom *asyh)
3862306a36Sopenharmony_ci{
3962306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
4062306a36Sopenharmony_ci	const int i = head->base.index;
4162306a36Sopenharmony_ci	int ret;
4262306a36Sopenharmony_ci
4362306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 3)))
4462306a36Sopenharmony_ci		return ret;
4562306a36Sopenharmony_ci
4662306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_CONTROL_OUTPUT_RESOURCE(i),
4762306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_OUTPUT_RESOURCE, CRC_MODE, asyh->or.crc_raster) |
4862306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_OUTPUT_RESOURCE, HSYNC_POLARITY, asyh->or.nhsync) |
4962306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_OUTPUT_RESOURCE, VSYNC_POLARITY, asyh->or.nvsync) |
5062306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_OUTPUT_RESOURCE, PIXEL_DEPTH, asyh->or.depth),
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ci				HEAD_SET_CONTROL(i), 0x31ec6000 | head->base.index << 25 |
5362306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL, STRUCTURE, asyh->mode.interlace));
5462306a36Sopenharmony_ci	return 0;
5562306a36Sopenharmony_ci}
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ciint
5862306a36Sopenharmony_cihead907d_procamp(struct nv50_head *head, struct nv50_head_atom *asyh)
5962306a36Sopenharmony_ci{
6062306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
6162306a36Sopenharmony_ci	const int i = head->base.index;
6262306a36Sopenharmony_ci	int ret;
6362306a36Sopenharmony_ci
6462306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 2)))
6562306a36Sopenharmony_ci		return ret;
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_PROCAMP(i),
6862306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PROCAMP, COLOR_SPACE, RGB) |
6962306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PROCAMP, CHROMA_LPF, AUTO) |
7062306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_PROCAMP, SAT_COS, asyh->procamp.sat.cos) |
7162306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_PROCAMP, SAT_SINE, asyh->procamp.sat.sin) |
7262306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PROCAMP, DYNAMIC_RANGE, VESA) |
7362306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PROCAMP, RANGE_COMPRESSION, DISABLE));
7462306a36Sopenharmony_ci	return 0;
7562306a36Sopenharmony_ci}
7662306a36Sopenharmony_ci
7762306a36Sopenharmony_cistatic int
7862306a36Sopenharmony_cihead907d_dither(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	if ((ret = PUSH_WAIT(push, 2)))
8562306a36Sopenharmony_ci		return ret;
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_DITHER_CONTROL(i),
8862306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_DITHER_CONTROL, ENABLE, asyh->dither.enable) |
8962306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_DITHER_CONTROL, BITS, asyh->dither.bits) |
9062306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_DITHER_CONTROL, MODE, asyh->dither.mode) |
9162306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_DITHER_CONTROL, PHASE, 0));
9262306a36Sopenharmony_ci	return 0;
9362306a36Sopenharmony_ci}
9462306a36Sopenharmony_ci
9562306a36Sopenharmony_ciint
9662306a36Sopenharmony_cihead907d_ovly(struct nv50_head *head, struct nv50_head_atom *asyh)
9762306a36Sopenharmony_ci{
9862306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
9962306a36Sopenharmony_ci	const int i = head->base.index;
10062306a36Sopenharmony_ci	u32 bounds = 0;
10162306a36Sopenharmony_ci	int ret;
10262306a36Sopenharmony_ci
10362306a36Sopenharmony_ci	if (asyh->ovly.cpp) {
10462306a36Sopenharmony_ci		switch (asyh->ovly.cpp) {
10562306a36Sopenharmony_ci		case 8: bounds |= NVDEF(NV907D, HEAD_SET_OVERLAY_USAGE_BOUNDS, PIXEL_DEPTH, BPP_64); break;
10662306a36Sopenharmony_ci		case 4: bounds |= NVDEF(NV907D, HEAD_SET_OVERLAY_USAGE_BOUNDS, PIXEL_DEPTH, BPP_32); break;
10762306a36Sopenharmony_ci		case 2: bounds |= NVDEF(NV907D, HEAD_SET_OVERLAY_USAGE_BOUNDS, PIXEL_DEPTH, BPP_16); break;
10862306a36Sopenharmony_ci		default:
10962306a36Sopenharmony_ci			WARN_ON(1);
11062306a36Sopenharmony_ci			break;
11162306a36Sopenharmony_ci		}
11262306a36Sopenharmony_ci		bounds |= NVDEF(NV907D, HEAD_SET_OVERLAY_USAGE_BOUNDS, USABLE, TRUE);
11362306a36Sopenharmony_ci	} else {
11462306a36Sopenharmony_ci		bounds |= NVDEF(NV907D, HEAD_SET_OVERLAY_USAGE_BOUNDS, PIXEL_DEPTH, BPP_16);
11562306a36Sopenharmony_ci	}
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 2)))
11862306a36Sopenharmony_ci		return ret;
11962306a36Sopenharmony_ci
12062306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_OVERLAY_USAGE_BOUNDS(i), bounds);
12162306a36Sopenharmony_ci	return 0;
12262306a36Sopenharmony_ci}
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_cistatic int
12562306a36Sopenharmony_cihead907d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
12662306a36Sopenharmony_ci{
12762306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
12862306a36Sopenharmony_ci	const int i = head->base.index;
12962306a36Sopenharmony_ci	u32 bounds = 0;
13062306a36Sopenharmony_ci	int ret;
13162306a36Sopenharmony_ci
13262306a36Sopenharmony_ci	if (asyh->base.cpp) {
13362306a36Sopenharmony_ci		switch (asyh->base.cpp) {
13462306a36Sopenharmony_ci		case 8: bounds |= NVDEF(NV907D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_64); break;
13562306a36Sopenharmony_ci		case 4: bounds |= NVDEF(NV907D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_32); break;
13662306a36Sopenharmony_ci		case 2: bounds |= NVDEF(NV907D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_16); break;
13762306a36Sopenharmony_ci		case 1: bounds |= NVDEF(NV907D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, PIXEL_DEPTH, BPP_8); break;
13862306a36Sopenharmony_ci		default:
13962306a36Sopenharmony_ci			WARN_ON(1);
14062306a36Sopenharmony_ci			break;
14162306a36Sopenharmony_ci		}
14262306a36Sopenharmony_ci		bounds |= NVDEF(NV907D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS, USABLE, TRUE);
14362306a36Sopenharmony_ci	}
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 2)))
14662306a36Sopenharmony_ci		return ret;
14762306a36Sopenharmony_ci
14862306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_BASE_CHANNEL_USAGE_BOUNDS(i), bounds);
14962306a36Sopenharmony_ci	return 0;
15062306a36Sopenharmony_ci}
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ciint
15362306a36Sopenharmony_cihead907d_curs_clr(struct nv50_head *head)
15462306a36Sopenharmony_ci{
15562306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
15662306a36Sopenharmony_ci	const int i = head->base.index;
15762306a36Sopenharmony_ci	int ret;
15862306a36Sopenharmony_ci
15962306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 4)))
16062306a36Sopenharmony_ci		return ret;
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_CONTROL_CURSOR(i),
16362306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_CONTROL_CURSOR, ENABLE, DISABLE) |
16462306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_CONTROL_CURSOR, FORMAT, A8R8G8B8) |
16562306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_CONTROL_CURSOR, SIZE, W64_H64));
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_CONTEXT_DMA_CURSOR(i), 0x00000000);
16862306a36Sopenharmony_ci	return 0;
16962306a36Sopenharmony_ci}
17062306a36Sopenharmony_ci
17162306a36Sopenharmony_ciint
17262306a36Sopenharmony_cihead907d_curs_set(struct nv50_head *head, struct nv50_head_atom *asyh)
17362306a36Sopenharmony_ci{
17462306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
17562306a36Sopenharmony_ci	const int i = head->base.index;
17662306a36Sopenharmony_ci	int ret;
17762306a36Sopenharmony_ci
17862306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 5)))
17962306a36Sopenharmony_ci		return ret;
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_CONTROL_CURSOR(i),
18262306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_CONTROL_CURSOR, ENABLE, ENABLE) |
18362306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_CURSOR, FORMAT, asyh->curs.format) |
18462306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_CURSOR, SIZE, asyh->curs.layout) |
18562306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_X, 0) |
18662306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_CURSOR, HOT_SPOT_Y, 0) |
18762306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_CONTROL_CURSOR, COMPOSITION, ALPHA_BLEND),
18862306a36Sopenharmony_ci
18962306a36Sopenharmony_ci				HEAD_SET_OFFSET_CURSOR(i), asyh->curs.offset >> 8);
19062306a36Sopenharmony_ci
19162306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_CONTEXT_DMA_CURSOR(i), asyh->curs.handle);
19262306a36Sopenharmony_ci	return 0;
19362306a36Sopenharmony_ci}
19462306a36Sopenharmony_ci
19562306a36Sopenharmony_ciint
19662306a36Sopenharmony_cihead907d_core_clr(struct nv50_head *head)
19762306a36Sopenharmony_ci{
19862306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
19962306a36Sopenharmony_ci	const int i = head->base.index;
20062306a36Sopenharmony_ci	int ret;
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 2)))
20362306a36Sopenharmony_ci		return ret;
20462306a36Sopenharmony_ci
20562306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_CONTEXT_DMAS_ISO(i), 0x00000000);
20662306a36Sopenharmony_ci	return 0;
20762306a36Sopenharmony_ci}
20862306a36Sopenharmony_ci
20962306a36Sopenharmony_ciint
21062306a36Sopenharmony_cihead907d_core_set(struct nv50_head *head, struct nv50_head_atom *asyh)
21162306a36Sopenharmony_ci{
21262306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
21362306a36Sopenharmony_ci	const int i = head->base.index;
21462306a36Sopenharmony_ci	int ret;
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 9)))
21762306a36Sopenharmony_ci		return ret;
21862306a36Sopenharmony_ci
21962306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_OFFSET(i),
22062306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_OFFSET, ORIGIN, asyh->core.offset >> 8));
22162306a36Sopenharmony_ci
22262306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_SIZE(i),
22362306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_SIZE, WIDTH, asyh->core.w) |
22462306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_SIZE, HEIGHT, asyh->core.h),
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci				HEAD_SET_STORAGE(i),
22762306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_STORAGE, BLOCK_HEIGHT, asyh->core.blockh) |
22862306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_STORAGE, PITCH, asyh->core.pitch >> 8) |
22962306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_STORAGE, PITCH, asyh->core.blocks) |
23062306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_STORAGE, MEMORY_LAYOUT, asyh->core.layout),
23162306a36Sopenharmony_ci
23262306a36Sopenharmony_ci				HEAD_SET_PARAMS(i),
23362306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_PARAMS, FORMAT, asyh->core.format) |
23462306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PARAMS, SUPER_SAMPLE, X1_AA) |
23562306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PARAMS, GAMMA, LINEAR),
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci				HEAD_SET_CONTEXT_DMAS_ISO(i),
23862306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTEXT_DMAS_ISO, HANDLE, asyh->core.handle));
23962306a36Sopenharmony_ci
24062306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_VIEWPORT_POINT_IN(i),
24162306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_POINT_IN, X, asyh->core.x) |
24262306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_POINT_IN, Y, asyh->core.y));
24362306a36Sopenharmony_ci	return 0;
24462306a36Sopenharmony_ci}
24562306a36Sopenharmony_ci
24662306a36Sopenharmony_ciint
24762306a36Sopenharmony_cihead907d_olut_clr(struct nv50_head *head)
24862306a36Sopenharmony_ci{
24962306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
25062306a36Sopenharmony_ci	const int i = head->base.index;
25162306a36Sopenharmony_ci	int ret;
25262306a36Sopenharmony_ci
25362306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 4)))
25462306a36Sopenharmony_ci		return ret;
25562306a36Sopenharmony_ci
25662306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_OUTPUT_LUT_LO(i),
25762306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_OUTPUT_LUT_LO, ENABLE, DISABLE));
25862306a36Sopenharmony_ci
25962306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_CONTEXT_DMA_LUT(i), 0x00000000);
26062306a36Sopenharmony_ci	return 0;
26162306a36Sopenharmony_ci}
26262306a36Sopenharmony_ci
26362306a36Sopenharmony_ciint
26462306a36Sopenharmony_cihead907d_olut_set(struct nv50_head *head, struct nv50_head_atom *asyh)
26562306a36Sopenharmony_ci{
26662306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
26762306a36Sopenharmony_ci	const int i = head->base.index;
26862306a36Sopenharmony_ci	int ret;
26962306a36Sopenharmony_ci
27062306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 5)))
27162306a36Sopenharmony_ci		return ret;
27262306a36Sopenharmony_ci
27362306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_OUTPUT_LUT_LO(i),
27462306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_OUTPUT_LUT_LO, ENABLE, ENABLE) |
27562306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_OUTPUT_LUT_LO, MODE, asyh->olut.mode) |
27662306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_OUTPUT_LUT_LO, NEVER_YIELD_TO_BASE, DISABLE),
27762306a36Sopenharmony_ci
27862306a36Sopenharmony_ci				HEAD_SET_OUTPUT_LUT_HI(i),
27962306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_OUTPUT_LUT_HI, ORIGIN, asyh->olut.offset >> 8));
28062306a36Sopenharmony_ci
28162306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_CONTEXT_DMA_LUT(i), asyh->olut.handle);
28262306a36Sopenharmony_ci	return 0;
28362306a36Sopenharmony_ci}
28462306a36Sopenharmony_ci
28562306a36Sopenharmony_civoid
28662306a36Sopenharmony_cihead907d_olut_load(struct drm_color_lut *in, int size, void __iomem *mem)
28762306a36Sopenharmony_ci{
28862306a36Sopenharmony_ci	for (; size--; in++, mem += 8) {
28962306a36Sopenharmony_ci		writew(drm_color_lut_extract(in->  red, 14) + 0x6000, mem + 0);
29062306a36Sopenharmony_ci		writew(drm_color_lut_extract(in->green, 14) + 0x6000, mem + 2);
29162306a36Sopenharmony_ci		writew(drm_color_lut_extract(in-> blue, 14) + 0x6000, mem + 4);
29262306a36Sopenharmony_ci	}
29362306a36Sopenharmony_ci
29462306a36Sopenharmony_ci	/* INTERPOLATE modes require a "next" entry to interpolate with,
29562306a36Sopenharmony_ci	 * so we replicate the last entry to deal with this for now.
29662306a36Sopenharmony_ci	 */
29762306a36Sopenharmony_ci	writew(readw(mem - 8), mem + 0);
29862306a36Sopenharmony_ci	writew(readw(mem - 6), mem + 2);
29962306a36Sopenharmony_ci	writew(readw(mem - 4), mem + 4);
30062306a36Sopenharmony_ci}
30162306a36Sopenharmony_ci
30262306a36Sopenharmony_cibool
30362306a36Sopenharmony_cihead907d_olut(struct nv50_head *head, struct nv50_head_atom *asyh, int size)
30462306a36Sopenharmony_ci{
30562306a36Sopenharmony_ci	if (size != 256 && size != 1024)
30662306a36Sopenharmony_ci		return false;
30762306a36Sopenharmony_ci
30862306a36Sopenharmony_ci	if (size == 1024)
30962306a36Sopenharmony_ci		asyh->olut.mode = NV907D_HEAD_SET_OUTPUT_LUT_LO_MODE_INTERPOLATE_1025_UNITY_RANGE;
31062306a36Sopenharmony_ci	else
31162306a36Sopenharmony_ci		asyh->olut.mode = NV907D_HEAD_SET_OUTPUT_LUT_LO_MODE_INTERPOLATE_257_UNITY_RANGE;
31262306a36Sopenharmony_ci
31362306a36Sopenharmony_ci	asyh->olut.load = head907d_olut_load;
31462306a36Sopenharmony_ci	return true;
31562306a36Sopenharmony_ci}
31662306a36Sopenharmony_ci
31762306a36Sopenharmony_cibool head907d_ilut_check(int size)
31862306a36Sopenharmony_ci{
31962306a36Sopenharmony_ci	return size == 256 || size == 1024;
32062306a36Sopenharmony_ci}
32162306a36Sopenharmony_ci
32262306a36Sopenharmony_ciint
32362306a36Sopenharmony_cihead907d_mode(struct nv50_head *head, struct nv50_head_atom *asyh)
32462306a36Sopenharmony_ci{
32562306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
32662306a36Sopenharmony_ci	struct nv50_head_mode *m = &asyh->mode;
32762306a36Sopenharmony_ci	const int i = head->base.index;
32862306a36Sopenharmony_ci	int ret;
32962306a36Sopenharmony_ci
33062306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 13)))
33162306a36Sopenharmony_ci		return ret;
33262306a36Sopenharmony_ci
33362306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_OVERSCAN_COLOR(i),
33462306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_OVERSCAN_COLOR, RED, 0) |
33562306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_OVERSCAN_COLOR, GRN, 0) |
33662306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_OVERSCAN_COLOR, BLU, 0),
33762306a36Sopenharmony_ci
33862306a36Sopenharmony_ci				HEAD_SET_RASTER_SIZE(i),
33962306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_SIZE, WIDTH, m->h.active) |
34062306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_SIZE, HEIGHT, m->v.active),
34162306a36Sopenharmony_ci
34262306a36Sopenharmony_ci				HEAD_SET_RASTER_SYNC_END(i),
34362306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_SYNC_END, X, m->h.synce) |
34462306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_SYNC_END, Y, m->v.synce),
34562306a36Sopenharmony_ci
34662306a36Sopenharmony_ci				HEAD_SET_RASTER_BLANK_END(i),
34762306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_BLANK_END, X, m->h.blanke) |
34862306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_BLANK_END, Y, m->v.blanke),
34962306a36Sopenharmony_ci
35062306a36Sopenharmony_ci				HEAD_SET_RASTER_BLANK_START(i),
35162306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_BLANK_START, X, m->h.blanks) |
35262306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_BLANK_START, Y, m->v.blanks),
35362306a36Sopenharmony_ci
35462306a36Sopenharmony_ci				HEAD_SET_RASTER_VERT_BLANK2(i),
35562306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_VERT_BLANK2, YSTART, m->v.blank2s) |
35662306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_RASTER_VERT_BLANK2, YEND, m->v.blank2e));
35762306a36Sopenharmony_ci
35862306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_DEFAULT_BASE_COLOR(i),
35962306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_DEFAULT_BASE_COLOR, RED, 0) |
36062306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_DEFAULT_BASE_COLOR, GREEN, 0) |
36162306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_DEFAULT_BASE_COLOR, BLUE, 0));
36262306a36Sopenharmony_ci
36362306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_PIXEL_CLOCK_FREQUENCY(i),
36462306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_PIXEL_CLOCK_FREQUENCY, HERTZ, m->clock * 1000) |
36562306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PIXEL_CLOCK_FREQUENCY, ADJ1000DIV1001, FALSE),
36662306a36Sopenharmony_ci
36762306a36Sopenharmony_ci				HEAD_SET_PIXEL_CLOCK_CONFIGURATION(i),
36862306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PIXEL_CLOCK_CONFIGURATION, MODE, CLK_CUSTOM) |
36962306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PIXEL_CLOCK_CONFIGURATION, NOT_DRIVER, FALSE) |
37062306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PIXEL_CLOCK_CONFIGURATION, ENABLE_HOPPING, FALSE),
37162306a36Sopenharmony_ci
37262306a36Sopenharmony_ci				HEAD_SET_PIXEL_CLOCK_FREQUENCY_MAX(i),
37362306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_PIXEL_CLOCK_FREQUENCY_MAX, HERTZ, m->clock * 1000) |
37462306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_PIXEL_CLOCK_FREQUENCY_MAX, ADJ1000DIV1001, FALSE));
37562306a36Sopenharmony_ci	return 0;
37662306a36Sopenharmony_ci}
37762306a36Sopenharmony_ci
37862306a36Sopenharmony_ciint
37962306a36Sopenharmony_cihead907d_view(struct nv50_head *head, struct nv50_head_atom *asyh)
38062306a36Sopenharmony_ci{
38162306a36Sopenharmony_ci	struct nvif_push *push = nv50_disp(head->base.base.dev)->core->chan.push;
38262306a36Sopenharmony_ci	const int i = head->base.index;
38362306a36Sopenharmony_ci	int ret;
38462306a36Sopenharmony_ci
38562306a36Sopenharmony_ci	if ((ret = PUSH_WAIT(push, 8)))
38662306a36Sopenharmony_ci		return ret;
38762306a36Sopenharmony_ci
38862306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER(i),
38962306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER, VERTICAL_TAPS, TAPS_1) |
39062306a36Sopenharmony_ci		  NVDEF(NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER, HORIZONTAL_TAPS, TAPS_1) |
39162306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER, HRESPONSE_BIAS, 0) |
39262306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_CONTROL_OUTPUT_SCALER, VRESPONSE_BIAS, 0));
39362306a36Sopenharmony_ci
39462306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_VIEWPORT_SIZE_IN(i),
39562306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_IN, WIDTH, asyh->view.iW) |
39662306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_IN, HEIGHT, asyh->view.iH));
39762306a36Sopenharmony_ci
39862306a36Sopenharmony_ci	PUSH_MTHD(push, NV907D, HEAD_SET_VIEWPORT_SIZE_OUT(i),
39962306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT, WIDTH, asyh->view.oW) |
40062306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT, HEIGHT, asyh->view.oH),
40162306a36Sopenharmony_ci
40262306a36Sopenharmony_ci				HEAD_SET_VIEWPORT_SIZE_OUT_MIN(i),
40362306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT_MIN, WIDTH, asyh->view.oW) |
40462306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT_MIN, HEIGHT, asyh->view.oH),
40562306a36Sopenharmony_ci
40662306a36Sopenharmony_ci				HEAD_SET_VIEWPORT_SIZE_OUT_MAX(i),
40762306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT_MAX, WIDTH, asyh->view.oW) |
40862306a36Sopenharmony_ci		  NVVAL(NV907D, HEAD_SET_VIEWPORT_SIZE_OUT_MAX, HEIGHT, asyh->view.oH));
40962306a36Sopenharmony_ci	return 0;
41062306a36Sopenharmony_ci}
41162306a36Sopenharmony_ci
41262306a36Sopenharmony_ciconst struct nv50_head_func
41362306a36Sopenharmony_cihead907d = {
41462306a36Sopenharmony_ci	.view = head907d_view,
41562306a36Sopenharmony_ci	.mode = head907d_mode,
41662306a36Sopenharmony_ci	.olut = head907d_olut,
41762306a36Sopenharmony_ci	.ilut_check = head907d_ilut_check,
41862306a36Sopenharmony_ci	.olut_size = 1024,
41962306a36Sopenharmony_ci	.olut_set = head907d_olut_set,
42062306a36Sopenharmony_ci	.olut_clr = head907d_olut_clr,
42162306a36Sopenharmony_ci	.core_calc = head507d_core_calc,
42262306a36Sopenharmony_ci	.core_set = head907d_core_set,
42362306a36Sopenharmony_ci	.core_clr = head907d_core_clr,
42462306a36Sopenharmony_ci	.curs_layout = head507d_curs_layout,
42562306a36Sopenharmony_ci	.curs_format = head507d_curs_format,
42662306a36Sopenharmony_ci	.curs_set = head907d_curs_set,
42762306a36Sopenharmony_ci	.curs_clr = head907d_curs_clr,
42862306a36Sopenharmony_ci	.base = head907d_base,
42962306a36Sopenharmony_ci	.ovly = head907d_ovly,
43062306a36Sopenharmony_ci	.dither = head907d_dither,
43162306a36Sopenharmony_ci	.procamp = head907d_procamp,
43262306a36Sopenharmony_ci	.or = head907d_or,
43362306a36Sopenharmony_ci};
434