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