xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/disp/nouveau_nvkm_engine_disp_headgf119.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_nvkm_engine_disp_headgf119.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2017 Red Hat Inc.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  *
24  * Authors: Ben Skeggs <bskeggs@redhat.com>
25  */
26 #include <sys/cdefs.h>
27 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_disp_headgf119.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $");
28 
29 #include "head.h"
30 
31 static void
gf119_head_vblank_put(struct nvkm_head * head)32 gf119_head_vblank_put(struct nvkm_head *head)
33 {
34 	struct nvkm_device *device = head->disp->engine.subdev.device;
35 	const u32 hoff = head->id * 0x800;
36 	nvkm_mask(device, 0x6100c0 + hoff, 0x00000001, 0x00000000);
37 }
38 
39 static void
gf119_head_vblank_get(struct nvkm_head * head)40 gf119_head_vblank_get(struct nvkm_head *head)
41 {
42 	struct nvkm_device *device = head->disp->engine.subdev.device;
43 	const u32 hoff = head->id * 0x800;
44 	nvkm_mask(device, 0x6100c0 + hoff, 0x00000001, 0x00000001);
45 }
46 
47 void
gf119_head_rgclk(struct nvkm_head * head,int div)48 gf119_head_rgclk(struct nvkm_head *head, int div)
49 {
50 	struct nvkm_device *device = head->disp->engine.subdev.device;
51 	nvkm_mask(device, 0x612200 + (head->id * 0x800), 0x0000000f, div);
52 }
53 
54 static void
gf119_head_state(struct nvkm_head * head,struct nvkm_head_state * state)55 gf119_head_state(struct nvkm_head *head, struct nvkm_head_state *state)
56 {
57 	struct nvkm_device *device = head->disp->engine.subdev.device;
58 	const u32 hoff = (state == &head->asy) * 0x20000 + head->id * 0x300;
59 	u32 data;
60 
61 	data = nvkm_rd32(device, 0x640414 + hoff);
62 	state->vtotal = (data & 0xffff0000) >> 16;
63 	state->htotal = (data & 0x0000ffff);
64 	data = nvkm_rd32(device, 0x640418 + hoff);
65 	state->vsynce = (data & 0xffff0000) >> 16;
66 	state->hsynce = (data & 0x0000ffff);
67 	data = nvkm_rd32(device, 0x64041c + hoff);
68 	state->vblanke = (data & 0xffff0000) >> 16;
69 	state->hblanke = (data & 0x0000ffff);
70 	data = nvkm_rd32(device, 0x640420 + hoff);
71 	state->vblanks = (data & 0xffff0000) >> 16;
72 	state->hblanks = (data & 0x0000ffff);
73 	state->hz = nvkm_rd32(device, 0x640450 + hoff);
74 
75 	data = nvkm_rd32(device, 0x640404 + hoff);
76 	switch ((data & 0x000003c0) >> 6) {
77 	case 6: state->or.depth = 30; break;
78 	case 5: state->or.depth = 24; break;
79 	case 2: state->or.depth = 18; break;
80 	case 0: state->or.depth = 18; break; /*XXX: "default" */
81 	default:
82 		state->or.depth = 18;
83 		WARN_ON(1);
84 		break;
85 	}
86 }
87 
88 static const struct nvkm_head_func
89 gf119_head = {
90 	.state = gf119_head_state,
91 	.rgpos = nv50_head_rgpos,
92 	.rgclk = gf119_head_rgclk,
93 	.vblank_get = gf119_head_vblank_get,
94 	.vblank_put = gf119_head_vblank_put,
95 };
96 
97 int
gf119_head_new(struct nvkm_disp * disp,int id)98 gf119_head_new(struct nvkm_disp *disp, int id)
99 {
100 	return nvkm_head_new_(&gf119_head, disp, id);
101 }
102 
103 int
gf119_head_cnt(struct nvkm_disp * disp,unsigned long * pmask)104 gf119_head_cnt(struct nvkm_disp *disp, unsigned long *pmask)
105 {
106 	struct nvkm_device *device = disp->engine.subdev.device;
107 	*pmask = nvkm_rd32(device, 0x612004) & 0x0000000f;
108 	return nvkm_rd32(device, 0x022448);
109 }
110