xref: /netbsd-src/sys/external/bsd/drm2/dist/drm/nouveau/nvkm/engine/disp/nouveau_nvkm_engine_disp_hdmigk104.c (revision 41ec02673d281bbb3d38e6c78504ce6e30c228c1)
1 /*	$NetBSD: nouveau_nvkm_engine_disp_hdmigk104.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $	*/
2 
3 /*
4  * Copyright 2014 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_hdmigk104.c,v 1.3 2021/12/18 23:45:35 riastradh Exp $");
28 
29 #include "hdmi.h"
30 
31 void
gk104_hdmi_ctrl(struct nvkm_ior * ior,int head,bool enable,u8 max_ac_packet,u8 rekey,u8 * avi,u8 avi_size,u8 * vendor,u8 vendor_size)32 gk104_hdmi_ctrl(struct nvkm_ior *ior, int head, bool enable, u8 max_ac_packet,
33 		u8 rekey, u8 *avi, u8 avi_size, u8 *vendor, u8 vendor_size)
34 {
35 	struct nvkm_device *device = ior->disp->engine.subdev.device;
36 	const u32 ctrl = 0x40000000 * enable |
37 			 max_ac_packet << 16 |
38 			 rekey;
39 	const u32 hoff = head * 0x800;
40 	const u32 hdmi = head * 0x400;
41 	struct packed_hdmi_infoframe avi_infoframe;
42 	struct packed_hdmi_infoframe vendor_infoframe;
43 
44 	pack_hdmi_infoframe(&avi_infoframe, avi, avi_size);
45 	pack_hdmi_infoframe(&vendor_infoframe, vendor, vendor_size);
46 
47 	if (!(ctrl & 0x40000000)) {
48 		nvkm_mask(device, 0x616798 + hoff, 0x40000000, 0x00000000);
49 		nvkm_mask(device, 0x690100 + hdmi, 0x00000001, 0x00000000);
50 		nvkm_mask(device, 0x6900c0 + hdmi, 0x00000001, 0x00000000);
51 		nvkm_mask(device, 0x690000 + hdmi, 0x00000001, 0x00000000);
52 		return;
53 	}
54 
55 	/* AVI InfoFrame */
56 	nvkm_mask(device, 0x690000 + hdmi, 0x00000001, 0x00000000);
57 	if (avi_size) {
58 		nvkm_wr32(device, 0x690008 + hdmi, avi_infoframe.header);
59 		nvkm_wr32(device, 0x69000c + hdmi, avi_infoframe.subpack0_low);
60 		nvkm_wr32(device, 0x690010 + hdmi, avi_infoframe.subpack0_high);
61 		nvkm_wr32(device, 0x690014 + hdmi, avi_infoframe.subpack1_low);
62 		nvkm_wr32(device, 0x690018 + hdmi, avi_infoframe.subpack1_high);
63 		nvkm_mask(device, 0x690000 + hdmi, 0x00000001, 0x00000001);
64 	}
65 
66 	/* GENERIC(?) / Vendor InfoFrame? */
67 	nvkm_mask(device, 0x690100 + hdmi, 0x00010001, 0x00000000);
68 	if (vendor_size) {
69 		nvkm_wr32(device, 0x690108 + hdmi, vendor_infoframe.header);
70 		nvkm_wr32(device, 0x69010c + hdmi, vendor_infoframe.subpack0_low);
71 		nvkm_wr32(device, 0x690110 + hdmi, vendor_infoframe.subpack0_high);
72 		/* Is there a second (or further?) set of subpack registers here? */
73 		nvkm_mask(device, 0x690100 + hdmi, 0x00000001, 0x00000001);
74 	}
75 
76 
77 	/* ??? InfoFrame? */
78 	nvkm_mask(device, 0x6900c0 + hdmi, 0x00000001, 0x00000000);
79 	nvkm_wr32(device, 0x6900cc + hdmi, 0x00000010);
80 	nvkm_mask(device, 0x6900c0 + hdmi, 0x00000001, 0x00000001);
81 
82 	/* ??? */
83 	nvkm_wr32(device, 0x690080 + hdmi, 0x82000000);
84 
85 	/* HDMI_CTRL */
86 	nvkm_mask(device, 0x616798 + hoff, 0x401f007f, ctrl);
87 }
88