2 * Copyright 2014 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 #include <subdev/bios.h>
28 #include <subdev/bios/dcb.h>
29 #include <subdev/i2c.h>
32 nvkm_outp_route(struct nvkm_disp *disp)
34 struct nvkm_outp *outp;
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);
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;
58 static enum nvkm_ior_proto
59 nvkm_outp_xlat(struct nvkm_outp *outp, enum nvkm_ior_type *type)
61 switch (outp->info.location) {
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;
74 switch (outp->info.type) {
75 case DCB_OUTPUT_TMDS: *type = PIOR; return TMDS;
76 case DCB_OUTPUT_DP : *type = PIOR; return TMDS; /* not a bug */
89 nvkm_outp_release(struct nvkm_outp *outp, u8 user)
91 struct nvkm_ior *ior = outp->ior;
92 OUTP_TRACE(outp, "release %02x &= %02x %p", outp->acquired, ~user, 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;
105 nvkm_outp_acquire_ior(struct nvkm_outp *outp, u8 user, struct nvkm_ior *ior)
108 outp->ior->asy.outp = outp;
109 outp->ior->asy.link = outp->info.sorconf.link;
110 outp->acquired |= user;
115 nvkm_outp_acquire(struct nvkm_outp *outp, u8 user)
117 struct nvkm_ior *ior = outp->ior;
118 enum nvkm_ior_proto proto;
119 enum nvkm_ior_type type;
121 OUTP_TRACE(outp, "acquire %02x |= %02x %p", outp->acquired, user, ior);
123 outp->acquired |= user;
127 /* Lookup a compatible, and unused, OR to assign to the device. */
128 proto = nvkm_outp_xlat(outp, &type);
129 if (proto == UNKNOWN)
132 /* Deal with panels requiring identity-mapped SOR assignment. */
133 if (outp->identity) {
134 ior = nvkm_ior_find(outp->disp, SOR, ffs(outp->info.or) - 1);
137 return nvkm_outp_acquire_ior(outp, user, ior);
140 /* First preference is to reuse the OR that is currently armed
141 * on HW, if any, in order to prevent unnecessary switching.
143 list_for_each_entry(ior, &outp->disp->ior, head) {
144 if (!ior->identity && !ior->asy.outp && ior->arm.outp == outp)
145 return nvkm_outp_acquire_ior(outp, user, ior);
148 /* Failing that, a completely unused OR is the next best thing. */
149 list_for_each_entry(ior, &outp->disp->ior, head) {
150 if (!ior->identity &&
151 !ior->asy.outp && ior->type == type && !ior->arm.outp &&
152 (ior->func->route.set || ior->id == __ffs(outp->info.or)))
153 return nvkm_outp_acquire_ior(outp, user, ior);
156 /* Last resort is to assign an OR that's already active on HW,
157 * but will be released during the next modeset.
159 list_for_each_entry(ior, &outp->disp->ior, head) {
160 if (!ior->identity && !ior->asy.outp && ior->type == type &&
161 (ior->func->route.set || ior->id == __ffs(outp->info.or)))
162 return nvkm_outp_acquire_ior(outp, user, ior);
169 nvkm_outp_fini(struct nvkm_outp *outp)
171 if (outp->func->fini)
172 outp->func->fini(outp);
176 nvkm_outp_init_route(struct nvkm_outp *outp)
178 struct nvkm_disp *disp = outp->disp;
179 enum nvkm_ior_proto proto;
180 enum nvkm_ior_type type;
181 struct nvkm_ior *ior;
184 /* Find any OR from the class that is able to support this device. */
185 proto = nvkm_outp_xlat(outp, &type);
186 if (proto == UNKNOWN)
189 ior = nvkm_ior_find(disp, type, -1);
195 /* Determine the specific OR, if any, this device is attached to. */
196 if (ior->func->route.get) {
197 id = ior->func->route.get(outp, &link);
199 OUTP_DBG(outp, "no route");
203 /* Prior to DCB 4.1, this is hardwired like so. */
204 id = ffs(outp->info.or) - 1;
205 link = (ior->type == SOR) ? outp->info.sorconf.link : 0;
208 ior = nvkm_ior_find(disp, type, id);
214 /* Determine if the OR is already configured for this device. */
215 ior->func->state(ior, &ior->arm);
216 if (!ior->arm.head || ior->arm.proto != proto) {
217 OUTP_DBG(outp, "no heads (%x %d %d)", ior->arm.head,
218 ior->arm.proto, proto);
222 OUTP_DBG(outp, "on %s link %x", ior->name, ior->arm.link);
223 ior->arm.outp = outp;
227 nvkm_outp_init(struct nvkm_outp *outp)
229 nvkm_outp_init_route(outp);
230 if (outp->func->init)
231 outp->func->init(outp);
235 nvkm_outp_del(struct nvkm_outp **poutp)
237 struct nvkm_outp *outp = *poutp;
238 if (outp && !WARN_ON(!outp->func)) {
239 if (outp->func->dtor)
240 *poutp = outp->func->dtor(outp);
247 nvkm_outp_ctor(const struct nvkm_outp_func *func, struct nvkm_disp *disp,
248 int index, struct dcb_output *dcbE, struct nvkm_outp *outp)
250 struct nvkm_i2c *i2c = disp->engine.subdev.device->i2c;
251 enum nvkm_ior_proto proto;
252 enum nvkm_ior_type type;
258 outp->i2c = nvkm_i2c_bus_find(i2c, dcbE->i2c_index);
260 OUTP_DBG(outp, "type %02x loc %d or %d link %d con %x "
261 "edid %x bus %d head %x",
262 outp->info.type, outp->info.location, outp->info.or,
263 outp->info.type >= 2 ? outp->info.sorconf.link : 0,
264 outp->info.connector, outp->info.i2c_index,
265 outp->info.bus, outp->info.heads);
267 /* Cull output paths we can't map to an output resource. */
268 proto = nvkm_outp_xlat(outp, &type);
269 if (proto == UNKNOWN)
275 static const struct nvkm_outp_func
280 nvkm_outp_new(struct nvkm_disp *disp, int index, struct dcb_output *dcbE,
281 struct nvkm_outp **poutp)
283 if (!(*poutp = kzalloc(sizeof(**poutp), GFP_KERNEL)))
285 return nvkm_outp_ctor(&nvkm_outp, disp, index, dcbE, *poutp);