Home | History | Annotate | Line # | Download | only in disp
      1 /*	$NetBSD: nouveau_nvkm_engine_disp_headgv100.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $	*/
      2 
      3 /*
      4  * Copyright 2018 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 #include <sys/cdefs.h>
     25 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_disp_headgv100.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $");
     26 
     27 #include "head.h"
     28 
     29 static void
     30 gv100_head_vblank_put(struct nvkm_head *head)
     31 {
     32 	struct nvkm_device *device = head->disp->engine.subdev.device;
     33 	nvkm_mask(device, 0x611d80 + (head->id * 4), 0x00000004, 0x00000000);
     34 }
     35 
     36 static void
     37 gv100_head_vblank_get(struct nvkm_head *head)
     38 {
     39 	struct nvkm_device *device = head->disp->engine.subdev.device;
     40 	nvkm_mask(device, 0x611d80 + (head->id * 4), 0x00000004, 0x00000004);
     41 }
     42 
     43 static void
     44 gv100_head_rgpos(struct nvkm_head *head, u16 *hline, u16 *vline)
     45 {
     46 	struct nvkm_device *device = head->disp->engine.subdev.device;
     47 	const u32 hoff = head->id * 0x800;
     48 	/* vline read locks hline. */
     49 	*vline = nvkm_rd32(device, 0x616330 + hoff) & 0x0000ffff;
     50 	*hline = nvkm_rd32(device, 0x616334 + hoff) & 0x0000ffff;
     51 }
     52 
     53 static void
     54 gv100_head_state(struct nvkm_head *head, struct nvkm_head_state *state)
     55 {
     56 	struct nvkm_device *device = head->disp->engine.subdev.device;
     57 	const u32 hoff = (state == &head->arm) * 0x8000 + head->id * 0x400;
     58 	u32 data;
     59 
     60 	data = nvkm_rd32(device, 0x682064 + hoff);
     61 	state->vtotal = (data & 0xffff0000) >> 16;
     62 	state->htotal = (data & 0x0000ffff);
     63 	data = nvkm_rd32(device, 0x682068 + hoff);
     64 	state->vsynce = (data & 0xffff0000) >> 16;
     65 	state->hsynce = (data & 0x0000ffff);
     66 	data = nvkm_rd32(device, 0x68206c + hoff);
     67 	state->vblanke = (data & 0xffff0000) >> 16;
     68 	state->hblanke = (data & 0x0000ffff);
     69 	data = nvkm_rd32(device, 0x682070 + hoff);
     70 	state->vblanks = (data & 0xffff0000) >> 16;
     71 	state->hblanks = (data & 0x0000ffff);
     72 	state->hz = nvkm_rd32(device, 0x68200c + hoff);
     73 
     74 	data = nvkm_rd32(device, 0x682004 + hoff);
     75 	switch ((data & 0x000000f0) >> 4) {
     76 	case 5: state->or.depth = 30; break;
     77 	case 4: state->or.depth = 24; break;
     78 	case 1: state->or.depth = 18; break;
     79 	default:
     80 		state->or.depth = 18;
     81 		WARN_ON(1);
     82 		break;
     83 	}
     84 }
     85 
     86 static const struct nvkm_head_func
     87 gv100_head = {
     88 	.state = gv100_head_state,
     89 	.rgpos = gv100_head_rgpos,
     90 	.rgclk = gf119_head_rgclk,
     91 	.vblank_get = gv100_head_vblank_get,
     92 	.vblank_put = gv100_head_vblank_put,
     93 };
     94 
     95 int
     96 gv100_head_new(struct nvkm_disp *disp, int id)
     97 {
     98 	struct nvkm_device *device = disp->engine.subdev.device;
     99 	if (!(nvkm_rd32(device, 0x610060) & (0x00000001 << id)))
    100 		return 0;
    101 	return nvkm_head_new_(&gv100_head, disp, id);
    102 }
    103 
    104 int
    105 gv100_head_cnt(struct nvkm_disp *disp, unsigned long *pmask)
    106 {
    107 	struct nvkm_device *device = disp->engine.subdev.device;
    108 	*pmask = nvkm_rd32(device, 0x610060) & 0x000000ff;
    109 	return nvkm_rd32(device, 0x610074) & 0x0000000f;
    110 }
    111