xref: /openbmc/linux/drivers/gpu/drm/nouveau/dispnv50/head917d.c (revision 131992709dc4c6140cec3b352f820cb873f7dd50)
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 
2509e1b78aSBen Skeggs static void
2609e1b78aSBen Skeggs head917d_dither(struct nv50_head *head, struct nv50_head_atom *asyh)
2709e1b78aSBen Skeggs {
2809e1b78aSBen Skeggs 	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
2909e1b78aSBen Skeggs 	u32 *push;
3009e1b78aSBen Skeggs 	if ((push = evo_wait(core, 2))) {
3109e1b78aSBen Skeggs 		evo_mthd(push, 0x04a0 + (head->base.index * 0x0300), 1);
3209e1b78aSBen Skeggs 		evo_data(push, asyh->dither.mode << 3 |
3309e1b78aSBen Skeggs 			       asyh->dither.bits << 1 |
3409e1b78aSBen Skeggs 			       asyh->dither.enable);
3509e1b78aSBen Skeggs 		evo_kick(push, core);
3609e1b78aSBen Skeggs 	}
3709e1b78aSBen Skeggs }
3809e1b78aSBen Skeggs 
39119608a7SBen Skeggs static void
40119608a7SBen Skeggs head917d_base(struct nv50_head *head, struct nv50_head_atom *asyh)
41119608a7SBen Skeggs {
42119608a7SBen Skeggs 	struct nv50_dmac *core = &nv50_disp(head->base.base.dev)->core->chan;
43119608a7SBen Skeggs 	u32 bounds = 0;
44119608a7SBen Skeggs 	u32 *push;
45119608a7SBen Skeggs 
46119608a7SBen Skeggs 	if (asyh->base.cpp) {
47119608a7SBen Skeggs 		switch (asyh->base.cpp) {
48119608a7SBen Skeggs 		case 8: bounds |= 0x00000500; break;
49119608a7SBen Skeggs 		case 4: bounds |= 0x00000300; break;
50119608a7SBen Skeggs 		case 2: bounds |= 0x00000100; break;
51119608a7SBen Skeggs 		case 1: bounds |= 0x00000000; break;
52119608a7SBen Skeggs 		default:
53119608a7SBen Skeggs 			WARN_ON(1);
54119608a7SBen Skeggs 			break;
55119608a7SBen Skeggs 		}
56119608a7SBen Skeggs 		bounds |= 0x00020001;
57119608a7SBen Skeggs 	}
58119608a7SBen Skeggs 
59119608a7SBen Skeggs 	if ((push = evo_wait(core, 2))) {
60119608a7SBen Skeggs 		evo_mthd(push, 0x04d0 + head->base.index * 0x300, 1);
61119608a7SBen Skeggs 		evo_data(push, bounds);
62119608a7SBen Skeggs 		evo_kick(push, core);
63119608a7SBen Skeggs 	}
64119608a7SBen Skeggs }
65119608a7SBen Skeggs 
66facaed62SBen Skeggs int
6701d380abSBen Skeggs head917d_curs_layout(struct nv50_head *head, struct nv50_wndw_atom *asyw,
6801d380abSBen Skeggs 		     struct nv50_head_atom *asyh)
6901d380abSBen Skeggs {
7001d380abSBen Skeggs 	switch (asyw->state.fb->width) {
7101d380abSBen Skeggs 	case  32: asyh->curs.layout = 0; break;
7201d380abSBen Skeggs 	case  64: asyh->curs.layout = 1; break;
7301d380abSBen Skeggs 	case 128: asyh->curs.layout = 2; break;
7401d380abSBen Skeggs 	case 256: asyh->curs.layout = 3; break;
7501d380abSBen Skeggs 	default:
7601d380abSBen Skeggs 		return -EINVAL;
7701d380abSBen Skeggs 	}
7801d380abSBen Skeggs 	return 0;
7901d380abSBen Skeggs }
8001d380abSBen Skeggs 
8109e1b78aSBen Skeggs const struct nv50_head_func
8209e1b78aSBen Skeggs head917d = {
8309e1b78aSBen Skeggs 	.view = head907d_view,
8409e1b78aSBen Skeggs 	.mode = head907d_mode,
85119608a7SBen Skeggs 	.olut = head907d_olut,
86*13199270SIlia Mirkin 	.olut_size = 1024,
87119608a7SBen Skeggs 	.olut_set = head907d_olut_set,
88119608a7SBen Skeggs 	.olut_clr = head907d_olut_clr,
8909e1b78aSBen Skeggs 	.core_calc = head507d_core_calc,
9009e1b78aSBen Skeggs 	.core_set = head907d_core_set,
9109e1b78aSBen Skeggs 	.core_clr = head907d_core_clr,
9201d380abSBen Skeggs 	.curs_layout = head917d_curs_layout,
9301d380abSBen Skeggs 	.curs_format = head507d_curs_format,
9409e1b78aSBen Skeggs 	.curs_set = head907d_curs_set,
9509e1b78aSBen Skeggs 	.curs_clr = head907d_curs_clr,
96119608a7SBen Skeggs 	.base = head917d_base,
9709e1b78aSBen Skeggs 	.ovly = head907d_ovly,
9809e1b78aSBen Skeggs 	.dither = head917d_dither,
9909e1b78aSBen Skeggs 	.procamp = head907d_procamp,
10009e1b78aSBen Skeggs 	.or = head907d_or,
10109e1b78aSBen Skeggs };
102