xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/disp/nouveau_nvkm_engine_disp_headnv50.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_nvkm_engine_disp_headnv50.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_headnv50.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $");
28 
29 #include "head.h"
30 
31 static void
nv50_head_vblank_put(struct nvkm_head * head)32 nv50_head_vblank_put(struct nvkm_head *head)
33 {
34 	struct nvkm_device *device = head->disp->engine.subdev.device;
35 	nvkm_mask(device, 0x61002c, (4 << head->id), 0);
36 }
37 
38 static void
nv50_head_vblank_get(struct nvkm_head * head)39 nv50_head_vblank_get(struct nvkm_head *head)
40 {
41 	struct nvkm_device *device = head->disp->engine.subdev.device;
42 	nvkm_mask(device, 0x61002c, (4 << head->id), (4 << head->id));
43 }
44 
45 static void
nv50_head_rgclk(struct nvkm_head * head,int div)46 nv50_head_rgclk(struct nvkm_head *head, int div)
47 {
48 	struct nvkm_device *device = head->disp->engine.subdev.device;
49 	nvkm_mask(device, 0x614200 + (head->id * 0x800), 0x0000000f, div);
50 }
51 
52 void
nv50_head_rgpos(struct nvkm_head * head,u16 * hline,u16 * vline)53 nv50_head_rgpos(struct nvkm_head *head, u16 *hline, u16 *vline)
54 {
55 	struct nvkm_device *device = head->disp->engine.subdev.device;
56 	const u32 hoff = head->id * 0x800;
57 	/* vline read locks hline. */
58 	*vline = nvkm_rd32(device, 0x616340 + hoff) & 0x0000ffff;
59 	*hline = nvkm_rd32(device, 0x616344 + hoff) & 0x0000ffff;
60 }
61 
62 static void
nv50_head_state(struct nvkm_head * head,struct nvkm_head_state * state)63 nv50_head_state(struct nvkm_head *head, struct nvkm_head_state *state)
64 {
65 	struct nvkm_device *device = head->disp->engine.subdev.device;
66 	const u32 hoff = head->id * 0x540 + (state == &head->arm) * 4;
67 	u32 data;
68 
69 	data = nvkm_rd32(device, 0x610ae8 + hoff);
70 	state->vblanke = (data & 0xffff0000) >> 16;
71 	state->hblanke = (data & 0x0000ffff);
72 	data = nvkm_rd32(device, 0x610af0 + hoff);
73 	state->vblanks = (data & 0xffff0000) >> 16;
74 	state->hblanks = (data & 0x0000ffff);
75 	data = nvkm_rd32(device, 0x610af8 + hoff);
76 	state->vtotal = (data & 0xffff0000) >> 16;
77 	state->htotal = (data & 0x0000ffff);
78 	data = nvkm_rd32(device, 0x610b00 + hoff);
79 	state->vsynce = (data & 0xffff0000) >> 16;
80 	state->hsynce = (data & 0x0000ffff);
81 	state->hz = (nvkm_rd32(device, 0x610ad0 + hoff) & 0x003fffff) * 1000;
82 }
83 
84 static const struct nvkm_head_func
85 nv50_head = {
86 	.state = nv50_head_state,
87 	.rgpos = nv50_head_rgpos,
88 	.rgclk = nv50_head_rgclk,
89 	.vblank_get = nv50_head_vblank_get,
90 	.vblank_put = nv50_head_vblank_put,
91 };
92 
93 int
nv50_head_new(struct nvkm_disp * disp,int id)94 nv50_head_new(struct nvkm_disp *disp, int id)
95 {
96 	return nvkm_head_new_(&nv50_head, disp, id);
97 }
98 
99 int
nv50_head_cnt(struct nvkm_disp * disp,unsigned long * pmask)100 nv50_head_cnt(struct nvkm_disp *disp, unsigned long *pmask)
101 {
102 	*pmask = 3;
103 	return 2;
104 }
105