1 /* $NetBSD: nouveau_nvkm_engine_disp_dacgf119.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 #include <sys/cdefs.h>
25 __KERNEL_RCSID(0, "$NetBSD: nouveau_nvkm_engine_disp_dacgf119.c,v 1.2 2021/12/18 23:45:35 riastradh Exp $");
26
27 #include "ior.h"
28
29 static void
gf119_dac_clock(struct nvkm_ior * dac)30 gf119_dac_clock(struct nvkm_ior *dac)
31 {
32 struct nvkm_device *device = dac->disp->engine.subdev.device;
33 const u32 doff = nv50_ior_base(dac);
34 nvkm_mask(device, 0x612280 + doff, 0x07070707, 0x00000000);
35 }
36
37 static void
gf119_dac_state(struct nvkm_ior * dac,struct nvkm_ior_state * state)38 gf119_dac_state(struct nvkm_ior *dac, struct nvkm_ior_state *state)
39 {
40 struct nvkm_device *device = dac->disp->engine.subdev.device;
41 const u32 coff = (state == &dac->asy) * 0x20000 + dac->id * 0x20;
42 u32 ctrl = nvkm_rd32(device, 0x640180 + coff);
43
44 state->proto_evo = (ctrl & 0x00000f00) >> 8;
45 switch (state->proto_evo) {
46 case 0: state->proto = CRT; break;
47 default:
48 state->proto = UNKNOWN;
49 break;
50 }
51
52 state->head = ctrl & 0x0000000f;
53 }
54
55 static const struct nvkm_ior_func
56 gf119_dac = {
57 .state = gf119_dac_state,
58 .power = nv50_dac_power,
59 .sense = nv50_dac_sense,
60 .clock = gf119_dac_clock,
61 };
62
63 int
gf119_dac_new(struct nvkm_disp * disp,int id)64 gf119_dac_new(struct nvkm_disp *disp, int id)
65 {
66 return nvkm_ior_new_(&gf119_dac, disp, DAC, id);
67 }
68
69 int
gf119_dac_cnt(struct nvkm_disp * disp,unsigned long * pmask)70 gf119_dac_cnt(struct nvkm_disp *disp, unsigned long *pmask)
71 {
72 struct nvkm_device *device = disp->engine.subdev.device;
73 *pmask = (nvkm_rd32(device, 0x612004) & 0x000000f0) >> 4;
74 return 4;
75 }
76