xref: /openbmc/linux/drivers/gpu/drm/nouveau/nvif/outp.c (revision 9793083f1dd9da8dda0ef68e90934dd7d112203b)
1 /*
2  * Copyright 2021 Red Hat Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  */
22 #include <nvif/outp.h>
23 #include <nvif/disp.h>
24 #include <nvif/printf.h>
25 
26 #include <nvif/class.h>
27 #include <nvif/if0012.h>
28 
29 void
30 nvif_outp_release(struct nvif_outp *outp)
31 {
32 	int ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_RELEASE, NULL, 0);
33 	NVIF_ERRON(ret, &outp->object, "[RELEASE]");
34 	outp->or.id = -1;
35 }
36 
37 static inline int
38 nvif_outp_acquire(struct nvif_outp *outp, u8 proto, struct nvif_outp_acquire_v0 *args)
39 {
40 	int ret;
41 
42 	args->version = 0;
43 	args->proto = proto;
44 
45 	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_ACQUIRE, args, sizeof(*args));
46 	if (ret)
47 		return ret;
48 
49 	outp->or.id = args->or;
50 	outp->or.link = args->link;
51 	return 0;
52 }
53 
54 int
55 nvif_outp_acquire_dp(struct nvif_outp *outp,  bool hda)
56 {
57 	struct nvif_outp_acquire_v0 args;
58 	int ret;
59 
60 	args.dp.hda = hda;
61 
62 	ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_DP, &args);
63 	NVIF_ERRON(ret, &outp->object,
64 		   "[ACQUIRE proto:DP hda:%d] or:%d link:%d", args.dp.hda, args.or, args.link);
65 	return ret;
66 }
67 
68 int
69 nvif_outp_acquire_lvds(struct nvif_outp *outp, bool dual, bool bpc8)
70 {
71 	struct nvif_outp_acquire_v0 args;
72 	int ret;
73 
74 	args.lvds.dual = dual;
75 	args.lvds.bpc8 = bpc8;
76 
77 	ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_LVDS, &args);
78 	NVIF_ERRON(ret, &outp->object,
79 		   "[ACQUIRE proto:LVDS dual:%d 8bpc:%d] or:%d link:%d",
80 		   args.lvds.dual, args.lvds.bpc8, args.or, args.link);
81 	return ret;
82 }
83 
84 int
85 nvif_outp_acquire_tmds(struct nvif_outp *outp, bool hda)
86 {
87 	struct nvif_outp_acquire_v0 args;
88 	int ret;
89 
90 	args.tmds.hda = hda;
91 
92 	ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_TMDS, &args);
93 	NVIF_ERRON(ret, &outp->object,
94 		   "[ACQUIRE proto:TMDS hda:%d] or:%d link:%d", args.tmds.hda, args.or, args.link);
95 	return ret;
96 }
97 
98 int
99 nvif_outp_acquire_rgb_crt(struct nvif_outp *outp)
100 {
101 	struct nvif_outp_acquire_v0 args;
102 	int ret;
103 
104 	ret = nvif_outp_acquire(outp, NVIF_OUTP_ACQUIRE_V0_RGB_CRT, &args);
105 	NVIF_ERRON(ret, &outp->object, "[ACQUIRE proto:RGB_CRT] or:%d", args.or);
106 	return ret;
107 }
108 
109 int
110 nvif_outp_load_detect(struct nvif_outp *outp, u32 loadval)
111 {
112 	struct nvif_outp_load_detect_v0 args;
113 	int ret;
114 
115 	args.version = 0;
116 	args.data = loadval;
117 
118 	ret = nvif_mthd(&outp->object, NVIF_OUTP_V0_LOAD_DETECT, &args, sizeof(args));
119 	NVIF_ERRON(ret, &outp->object, "[LOAD_DETECT data:%08x] load:%02x", args.data, args.load);
120 	return ret < 0 ? ret : args.load;
121 }
122 
123 void
124 nvif_outp_dtor(struct nvif_outp *outp)
125 {
126 	nvif_object_dtor(&outp->object);
127 }
128 
129 int
130 nvif_outp_ctor(struct nvif_disp *disp, const char *name, int id, struct nvif_outp *outp)
131 {
132 	struct nvif_outp_v0 args;
133 	int ret;
134 
135 	args.version = 0;
136 	args.id = id;
137 
138 	ret = nvif_object_ctor(&disp->object, name ?: "nvifOutp", id, NVIF_CLASS_OUTP,
139 			       &args, sizeof(args), &outp->object);
140 	NVIF_ERRON(ret, &disp->object, "[NEW outp id:%d]", id);
141 	if (ret)
142 		return ret;
143 
144 	outp->or.id = -1;
145 	return 0;
146 }
147