xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvif/outp.c (revision ea6143a86c67110a2c62deaf70d0b7b92e4f865f)
11b255f1cSBen Skeggs /*
21b255f1cSBen Skeggs  * Copyright 2021 Red Hat Inc.
31b255f1cSBen Skeggs  *
41b255f1cSBen Skeggs  * Permission is hereby granted, free of charge, to any person obtaining a
51b255f1cSBen Skeggs  * copy of this software and associated documentation files (the "Software"),
61b255f1cSBen Skeggs  * to deal in the Software without restriction, including without limitation
71b255f1cSBen Skeggs  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
81b255f1cSBen Skeggs  * and/or sell copies of the Software, and to permit persons to whom the
91b255f1cSBen Skeggs  * Software is furnished to do so, subject to the following conditions:
101b255f1cSBen Skeggs  *
111b255f1cSBen Skeggs  * The above copyright notice and this permission notice shall be included in
121b255f1cSBen Skeggs  * all copies or substantial portions of the Software.
131b255f1cSBen Skeggs  *
141b255f1cSBen Skeggs  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
151b255f1cSBen Skeggs  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
161b255f1cSBen Skeggs  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
171b255f1cSBen Skeggs  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
181b255f1cSBen Skeggs  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
191b255f1cSBen Skeggs  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
201b255f1cSBen Skeggs  * OTHER DEALINGS IN THE SOFTWARE.
211b255f1cSBen Skeggs  */
221b255f1cSBen Skeggs #include <nvif/outp.h>
231b255f1cSBen Skeggs #include <nvif/disp.h>
241b255f1cSBen Skeggs #include <nvif/printf.h>
251b255f1cSBen Skeggs 
261b255f1cSBen Skeggs #include <nvif/class.h>
271b255f1cSBen Skeggs #include <nvif/if0012.h>
281b255f1cSBen Skeggs 
29*ea6143a8SBen Skeggs void
30*ea6143a8SBen Skeggs nvif_outp_release(struct nvif_outp *outp)
31*ea6143a8SBen Skeggs {
32*ea6143a8SBen Skeggs 	int ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_RELEASE, NULL, 0);
33*ea6143a8SBen Skeggs 	NVIF_ERRON(ret, &outp->object, "[RELEASE]");
34*ea6143a8SBen Skeggs 	outp->or.id = -1;
35*ea6143a8SBen Skeggs }
36*ea6143a8SBen Skeggs 
37*ea6143a8SBen Skeggs static inline int
38*ea6143a8SBen Skeggs nvif_outp_acquire(struct nvif_outp *outp, u8 proto, struct nvif_outp_acquire_v0 *args)
39*ea6143a8SBen Skeggs {
40*ea6143a8SBen Skeggs 	int ret;
41*ea6143a8SBen Skeggs 
42*ea6143a8SBen Skeggs 	args->version = 0;
43*ea6143a8SBen Skeggs 	args->proto = proto;
44*ea6143a8SBen Skeggs 
45*ea6143a8SBen Skeggs 	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_ACQUIRE, args, sizeof(*args));
46*ea6143a8SBen Skeggs 	if (ret)
47*ea6143a8SBen Skeggs 		return ret;
48*ea6143a8SBen Skeggs 
49*ea6143a8SBen Skeggs 	outp->or.id = args->or;
50*ea6143a8SBen Skeggs 	outp->or.link = args->link;
51*ea6143a8SBen Skeggs 	return 0;
52*ea6143a8SBen Skeggs }
53*ea6143a8SBen Skeggs 
54*ea6143a8SBen Skeggs int
55*ea6143a8SBen Skeggs nvif_outp_acquire_dp(struct nvif_outp *outp,  bool hda)
56*ea6143a8SBen Skeggs {
57*ea6143a8SBen Skeggs 	struct nvif_outp_acquire_v0 args;
58*ea6143a8SBen Skeggs 	int ret;
59*ea6143a8SBen Skeggs 
60*ea6143a8SBen Skeggs 	args.dp.hda = hda;
61*ea6143a8SBen Skeggs 
62*ea6143a8SBen Skeggs 	ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_DP, &args);
63*ea6143a8SBen Skeggs 	NVIF_ERRON(ret, &outp->object,
64*ea6143a8SBen Skeggs 		   "[ACQUIRE proto:DP hda:%d] or:%d link:%d", args.dp.hda, args.or, args.link);
65*ea6143a8SBen Skeggs 	return ret;
66*ea6143a8SBen Skeggs }
67*ea6143a8SBen Skeggs 
68*ea6143a8SBen Skeggs int
69*ea6143a8SBen Skeggs nvif_outp_acquire_lvds(struct nvif_outp *outp)
70*ea6143a8SBen Skeggs {
71*ea6143a8SBen Skeggs 	struct nvif_outp_acquire_v0 args;
72*ea6143a8SBen Skeggs 	int ret;
73*ea6143a8SBen Skeggs 
74*ea6143a8SBen Skeggs 	ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_LVDS, &args);
75*ea6143a8SBen Skeggs 	NVIF_ERRON(ret, &outp->object, "[ACQUIRE proto:LVDS] or:%d link:%d", args.or, args.link);
76*ea6143a8SBen Skeggs 	return ret;
77*ea6143a8SBen Skeggs }
78*ea6143a8SBen Skeggs 
79*ea6143a8SBen Skeggs int
80*ea6143a8SBen Skeggs nvif_outp_acquire_tmds(struct nvif_outp *outp, bool hda)
81*ea6143a8SBen Skeggs {
82*ea6143a8SBen Skeggs 	struct nvif_outp_acquire_v0 args;
83*ea6143a8SBen Skeggs 	int ret;
84*ea6143a8SBen Skeggs 
85*ea6143a8SBen Skeggs 	args.tmds.hda = hda;
86*ea6143a8SBen Skeggs 
87*ea6143a8SBen Skeggs 	ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_TMDS, &args);
88*ea6143a8SBen Skeggs 	NVIF_ERRON(ret, &outp->object,
89*ea6143a8SBen Skeggs 		   "[ACQUIRE proto:TMDS hda:%d] or:%d link:%d", args.tmds.hda, args.or, args.link);
90*ea6143a8SBen Skeggs 	return ret;
91*ea6143a8SBen Skeggs }
92*ea6143a8SBen Skeggs 
93*ea6143a8SBen Skeggs int
94*ea6143a8SBen Skeggs nvif_outp_acquire_rgb_crt(struct nvif_outp *outp)
95*ea6143a8SBen Skeggs {
96*ea6143a8SBen Skeggs 	struct nvif_outp_acquire_v0 args;
97*ea6143a8SBen Skeggs 	int ret;
98*ea6143a8SBen Skeggs 
99*ea6143a8SBen Skeggs 	ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_RGB_CRT, &args);
100*ea6143a8SBen Skeggs 	NVIF_ERRON(ret, &outp->object, "[ACQUIRE proto:RGB_CRT] or:%d", args.or);
101*ea6143a8SBen Skeggs 	return ret;
102*ea6143a8SBen Skeggs }
103*ea6143a8SBen Skeggs 
104dfc4005fSBen Skeggs int
105dfc4005fSBen Skeggs nvif_outp_load_detect(struct nvif_outp *outp, u32 loadval)
106dfc4005fSBen Skeggs {
107dfc4005fSBen Skeggs 	struct nvif_outp_load_detect_v0 args;
108dfc4005fSBen Skeggs 	int ret;
109dfc4005fSBen Skeggs 
110dfc4005fSBen Skeggs 	args.version = 0;
111dfc4005fSBen Skeggs 	args.data = loadval;
112dfc4005fSBen Skeggs 
113dfc4005fSBen Skeggs 	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_LOAD_DETECT, &args, sizeof(args));
114dfc4005fSBen Skeggs 	NVIF_ERRON(ret, &outp->object, "[LOAD_DETECT data:%08x] load:%02x", args.data, args.load);
115dfc4005fSBen Skeggs 	return ret < 0 ? ret : args.load;
116dfc4005fSBen Skeggs }
117dfc4005fSBen Skeggs 
1181b255f1cSBen Skeggs void
1191b255f1cSBen Skeggs nvif_outp_dtor(struct nvif_outp *outp)
1201b255f1cSBen Skeggs {
1211b255f1cSBen Skeggs 	nvif_object_dtor(&outp->object);
1221b255f1cSBen Skeggs }
1231b255f1cSBen Skeggs 
1241b255f1cSBen Skeggs int
1251b255f1cSBen Skeggs nvif_outp_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_outp *outp)
1261b255f1cSBen Skeggs {
1271b255f1cSBen Skeggs 	struct nvif_outp_v0 args;
1281b255f1cSBen Skeggs 	int ret;
1291b255f1cSBen Skeggs 
1301b255f1cSBen Skeggs 	args.version = 0;
1311b255f1cSBen Skeggs 	args.id = id;
1321b255f1cSBen Skeggs 
1331b255f1cSBen Skeggs 	ret = nvif_object_ctor(&disp->object, name ?: "nvifOutp", id, NVIF_CLASS_OUTP,
1341b255f1cSBen Skeggs 			       &args, sizeof(args), &outp->object);
1351b255f1cSBen Skeggs 	NVIF_ERRON(ret, &disp->object, "[NEW outp id:%d]", id);
136*ea6143a8SBen Skeggs 	if (ret)
1371b255f1cSBen Skeggs 		return ret;
138*ea6143a8SBen Skeggs 
139*ea6143a8SBen Skeggs 	outp->or.id = -1;
140*ea6143a8SBen Skeggs 	return 0;
1411b255f1cSBen Skeggs }
142