1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "outp.h"
25#include "dp.h"
26#include "ior.h"
27
28#include <subdev/bios.h>
29#include <subdev/bios/dcb.h>
30#include <subdev/i2c.h>
31
32void
33nvkm_outp_route(struct nvkm_disp *disp)
34{
35 struct nvkm_outp *outp;
36 struct nvkm_ior *ior;
37
38 list_for_each_entry(ior, &disp->ior, head) {
39 if ((outp = ior->arm.outp) && ior->arm.outp != ior->asy.outp) {
40 OUTP_DBG(outp, "release %s", ior->name);
41 if (ior->func->route.set)
42 ior->func->route.set(outp, NULL);
43 ior->arm.outp = NULL;
44 }
45 }
46
47 list_for_each_entry(ior, &disp->ior, head) {
48 if ((outp = ior->asy.outp)) {
49 OUTP_DBG(outp, "acquire %s", ior->name);
50 if (ior->asy.outp != ior->arm.outp) {
51 if (ior->func->route.set)
52 ior->func->route.set(outp, ior);
53 ior->arm.outp = ior->asy.outp;
54 }
55 }
56 }
57}
58
59static enum nvkm_ior_proto
60nvkm_outp_xlat(struct nvkm_outp *outp, enum nvkm_ior_type *type)
61{
62 switch (outp->info.location) {
63 case 0:
64 switch (outp->info.type) {
65 case DCB_OUTPUT_ANALOG: *type = DAC; return CRT;
66 case DCB_OUTPUT_TV : *type = DAC; return TV;
67 case DCB_OUTPUT_TMDS : *type = SOR; return TMDS;
68 case DCB_OUTPUT_LVDS : *type = SOR; return LVDS;
69 case DCB_OUTPUT_DP : *type = SOR; return DP;
70 default:
71 break;
72 }
73 break;
74 case 1:
75 switch (outp->info.type) {
76 case DCB_OUTPUT_TMDS: *type = PIOR; return TMDS;
77 case DCB_OUTPUT_DP : *type = PIOR; return TMDS;
78 default:
79 break;
80 }
81 break;
82 default:
83 break;
84 }
85 WARN_ON(1);
86 return UNKNOWN;
87}
88
89void
90nvkm_outp_release(struct nvkm_outp *outp, u8 user)
91{
92 struct nvkm_ior *ior = outp->ior;
93 OUTP_TRACE(outp, "release %02x &= %02x %p", outp->acquired, ~user, ior);
94 if (ior) {
95 outp->acquired &= ~user;
96 if (!outp->acquired) {
97 if (outp->func->release && outp->ior)
98 outp->func->release(outp);
99 outp->ior->asy.outp = NULL;
100 outp->ior = NULL;
101 }
102 }
103}
104
105static inline int
106nvkm_outp_acquire_ior(struct nvkm_outp *outp, u8 user, struct nvkm_ior *ior)
107{
108 outp->ior = ior;
109 outp->ior->asy.outp = outp;
110 outp->ior->asy.link = outp->info.sorconf.link;
111 outp->acquired |= user;
112 return 0;
113}
114
115static inline int
116nvkm_outp_acquire_hda(struct nvkm_outp *outp, enum nvkm_ior_type type,
117 u8 user, bool hda)
118{
119 struct nvkm_ior *ior;
120
121
122 list_for_each_entry(ior, &outp->disp->ior, head) {
123 if (!ior->identity && !!ior->func->hda.hpd == hda &&
124 !ior->asy.outp && ior->type == type && !ior->arm.outp &&
125 (ior->func->route.set || ior->id == __ffs(outp->info.or)))
126 return nvkm_outp_acquire_ior(outp, user, ior);
127 }
128
129
130
131
132 list_for_each_entry(ior, &outp->disp->ior, head) {
133 if (!ior->identity && !!ior->func->hda.hpd == hda &&
134 !ior->asy.outp && ior->type == type &&
135 (ior->func->route.set || ior->id == __ffs(outp->info.or)))
136 return nvkm_outp_acquire_ior(outp, user, ior);
137 }
138
139 return -ENOSPC;
140}
141
142int
143nvkm_outp_acquire(struct nvkm_outp *outp, u8 user, bool hda)
144{
145 struct nvkm_ior *ior = outp->ior;
146 enum nvkm_ior_proto proto;
147 enum nvkm_ior_type type;
148
149 OUTP_TRACE(outp, "acquire %02x |= %02x %p", outp->acquired, user, ior);
150 if (ior) {
151 outp->acquired |= user;
152 return 0;
153 }
154
155
156 proto = nvkm_outp_xlat(outp, &type);
157 if (proto == UNKNOWN)
158 return -ENOSYS;
159
160
161 if (outp->identity) {
162 ior = nvkm_ior_find(outp->disp, SOR, ffs(outp->info.or) - 1);
163 if (WARN_ON(!ior))
164 return -ENOSPC;
165 return nvkm_outp_acquire_ior(outp, user, ior);
166 }
167
168
169
170
171 list_for_each_entry(ior, &outp->disp->ior, head) {
172 if (!ior->identity && !ior->asy.outp && ior->arm.outp == outp) {
173
174
175
176
177
178
179
180
181
182
183
184 WARN_ON(hda && !ior->func->hda.hpd);
185 return nvkm_outp_acquire_ior(outp, user, ior);
186 }
187 }
188
189
190
191
192 if (!hda) {
193 if (!nvkm_outp_acquire_hda(outp, type, user, false))
194 return 0;
195
196
197 return nvkm_outp_acquire_hda(outp, type, user, true);
198 }
199
200
201 if (!nvkm_outp_acquire_hda(outp, type, user, true))
202 return 0;
203
204
205
206
207 return nvkm_outp_acquire_hda(outp, type, user, false);
208}
209
210void
211nvkm_outp_fini(struct nvkm_outp *outp)
212{
213 if (outp->func->fini)
214 outp->func->fini(outp);
215}
216
217static void
218nvkm_outp_init_route(struct nvkm_outp *outp)
219{
220 struct nvkm_disp *disp = outp->disp;
221 enum nvkm_ior_proto proto;
222 enum nvkm_ior_type type;
223 struct nvkm_ior *ior;
224 int id, link;
225
226
227 proto = nvkm_outp_xlat(outp, &type);
228 if (proto == UNKNOWN)
229 return;
230
231 ior = nvkm_ior_find(disp, type, -1);
232 if (!ior) {
233 WARN_ON(1);
234 return;
235 }
236
237
238 if (ior->func->route.get) {
239 id = ior->func->route.get(outp, &link);
240 if (id < 0) {
241 OUTP_DBG(outp, "no route");
242 return;
243 }
244 } else {
245
246 id = ffs(outp->info.or) - 1;
247 link = (ior->type == SOR) ? outp->info.sorconf.link : 0;
248 }
249
250 ior = nvkm_ior_find(disp, type, id);
251 if (!ior) {
252 WARN_ON(1);
253 return;
254 }
255
256
257 ior->func->state(ior, &ior->arm);
258 if (!ior->arm.head || ior->arm.proto != proto) {
259 OUTP_DBG(outp, "no heads (%x %d %d)", ior->arm.head,
260 ior->arm.proto, proto);
261
262
263
264
265
266 if (ior->func->route.get && !ior->arm.head && outp->info.type == DCB_OUTPUT_DP)
267 nvkm_dp_disable(outp, ior);
268
269 return;
270 }
271
272 OUTP_DBG(outp, "on %s link %x", ior->name, ior->arm.link);
273 ior->arm.outp = outp;
274}
275
276void
277nvkm_outp_init(struct nvkm_outp *outp)
278{
279 nvkm_outp_init_route(outp);
280 if (outp->func->init)
281 outp->func->init(outp);
282}
283
284void
285nvkm_outp_del(struct nvkm_outp **poutp)
286{
287 struct nvkm_outp *outp = *poutp;
288 if (outp && !WARN_ON(!outp->func)) {
289 if (outp->func->dtor)
290 *poutp = outp->func->dtor(outp);
291 kfree(*poutp);
292 *poutp = NULL;
293 }
294}
295
296int
297nvkm_outp_ctor(const struct nvkm_outp_func *func, struct nvkm_disp *disp,
298 int index, struct dcb_output *dcbE, struct nvkm_outp *outp)
299{
300 struct nvkm_i2c *i2c = disp->engine.subdev.device->i2c;
301 enum nvkm_ior_proto proto;
302 enum nvkm_ior_type type;
303
304 outp->func = func;
305 outp->disp = disp;
306 outp->index = index;
307 outp->info = *dcbE;
308 outp->i2c = nvkm_i2c_bus_find(i2c, dcbE->i2c_index);
309
310 OUTP_DBG(outp, "type %02x loc %d or %d link %d con %x "
311 "edid %x bus %d head %x",
312 outp->info.type, outp->info.location, outp->info.or,
313 outp->info.type >= 2 ? outp->info.sorconf.link : 0,
314 outp->info.connector, outp->info.i2c_index,
315 outp->info.bus, outp->info.heads);
316
317
318 proto = nvkm_outp_xlat(outp, &type);
319 if (proto == UNKNOWN)
320 return -ENODEV;
321
322 return 0;
323}
324
325static const struct nvkm_outp_func
326nvkm_outp = {
327};
328
329int
330nvkm_outp_new(struct nvkm_disp *disp, int index, struct dcb_output *dcbE,
331 struct nvkm_outp **poutp)
332{
333 if (!(*poutp = kzalloc(sizeof(**poutp), GFP_KERNEL)))
334 return -ENOMEM;
335 return nvkm_outp_ctor(&nvkm_outp, disp, index, dcbE, *poutp);
336}
337