1/*	$NetBSD: nouveau_nvkm_engine_disp_headnv04.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_headnv04.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $");
28
29#include "head.h"
30
31static void
32nv04_head_vblank_put(struct nvkm_head *head)
33{
34	struct nvkm_device *device = head->disp->engine.subdev.device;
35	nvkm_wr32(device, 0x600140 + (head->id * 0x2000) , 0x00000000);
36}
37
38static void
39nv04_head_vblank_get(struct nvkm_head *head)
40{
41	struct nvkm_device *device = head->disp->engine.subdev.device;
42	nvkm_wr32(device, 0x600140 + (head->id * 0x2000) , 0x00000001);
43}
44
45static void
46nv04_head_rgpos(struct nvkm_head *head, u16 *hline, u16 *vline)
47{
48	struct nvkm_device *device = head->disp->engine.subdev.device;
49	u32 data = nvkm_rd32(device, 0x600868 + (head->id * 0x2000));
50	*hline = (data & 0xffff0000) >> 16;
51	*vline = (data & 0x0000ffff);
52}
53
54static void
55nv04_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 = head->id * 0x0200;
59	state->vblanks = nvkm_rd32(device, 0x680800 + hoff) & 0x0000ffff;
60	state->vtotal  = nvkm_rd32(device, 0x680804 + hoff) & 0x0000ffff;
61	state->vblanke = state->vtotal - 1;
62	state->hblanks = nvkm_rd32(device, 0x680820 + hoff) & 0x0000ffff;
63	state->htotal  = nvkm_rd32(device, 0x680824 + hoff) & 0x0000ffff;
64	state->hblanke = state->htotal - 1;
65}
66
67static const struct nvkm_head_func
68nv04_head = {
69	.state = nv04_head_state,
70	.rgpos = nv04_head_rgpos,
71	.vblank_get = nv04_head_vblank_get,
72	.vblank_put = nv04_head_vblank_put,
73};
74
75int
76nv04_head_new(struct nvkm_disp *disp, int id)
77{
78	return nvkm_head_new_(&nv04_head, disp, id);
79}
80