1/*	$NetBSD: nouveau_nvkm_engine_disp_piocgf119.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $	*/
2
3/*
4 * Copyright 2012 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
25 */
26#include <sys/cdefs.h>
27__KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_disp_piocgf119.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $");
28
29#include "channv50.h"
30#include "rootnv50.h"
31
32#include <subdev/timer.h>
33
34static void
35gf119_disp_pioc_fini(struct nv50_disp_chan *chan)
36{
37	struct nv50_disp *disp = chan->disp;
38	struct nvkm_subdev *subdev = &disp->base.engine.subdev;
39	struct nvkm_device *device = subdev->device;
40	int ctrl = chan->chid.ctrl;
41	int user = chan->chid.user;
42
43	nvkm_mask(device, 0x610490 + (ctrl * 0x10), 0x00000001, 0x00000000);
44	if (nvkm_msec(device, 2000,
45		if (!(nvkm_rd32(device, 0x610490 + (ctrl * 0x10)) & 0x00030000))
46			break;
47	) < 0) {
48		nvkm_error(subdev, "ch %d fini: %08x\n", user,
49			   nvkm_rd32(device, 0x610490 + (ctrl * 0x10)));
50	}
51}
52
53static int
54gf119_disp_pioc_init(struct nv50_disp_chan *chan)
55{
56	struct nv50_disp *disp = chan->disp;
57	struct nvkm_subdev *subdev = &disp->base.engine.subdev;
58	struct nvkm_device *device = subdev->device;
59	int ctrl = chan->chid.ctrl;
60	int user = chan->chid.user;
61
62	/* activate channel */
63	nvkm_wr32(device, 0x610490 + (ctrl * 0x10), 0x00000001);
64	if (nvkm_msec(device, 2000,
65		u32 tmp = nvkm_rd32(device, 0x610490 + (ctrl * 0x10));
66		if ((tmp & 0x00030000) == 0x00010000)
67			break;
68	) < 0) {
69		nvkm_error(subdev, "ch %d init: %08x\n", user,
70			   nvkm_rd32(device, 0x610490 + (ctrl * 0x10)));
71		return -EBUSY;
72	}
73
74	return 0;
75}
76
77const struct nv50_disp_chan_func
78gf119_disp_pioc_func = {
79	.init = gf119_disp_pioc_init,
80	.fini = gf119_disp_pioc_fini,
81	.intr = gf119_disp_chan_intr,
82	.user = nv50_disp_chan_user,
83};
84