1 /*
2 * Copyright 2014 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 * Authors: Ben Skeggs
23 */
24 #include "outp.h"
25
26 #include <subdev/bios.h>
27 #include <subdev/bios/dcb.h>
28 #include <subdev/i2c.h>
29
30 void
nvkm_output_fini(struct nvkm_output * outp)31 nvkm_output_fini(struct nvkm_output *outp)
32 {
33 if (outp->func->fini)
34 outp->func->fini(outp);
35 }
36
37 void
nvkm_output_init(struct nvkm_output * outp)38 nvkm_output_init(struct nvkm_output *outp)
39 {
40 if (outp->func->init)
41 outp->func->init(outp);
42 }
43
44 void
nvkm_output_del(struct nvkm_output ** poutp)45 nvkm_output_del(struct nvkm_output **poutp)
46 {
47 struct nvkm_output *outp = *poutp;
48 if (outp && !WARN_ON(!outp->func)) {
49 if (outp->func->dtor)
50 *poutp = outp->func->dtor(outp);
51 kfree(*poutp);
52 *poutp = NULL;
53 }
54 }
55
56 void
nvkm_output_ctor(const struct nvkm_output_func * func,struct nvkm_disp * disp,int index,struct dcb_output * dcbE,struct nvkm_output * outp)57 nvkm_output_ctor(const struct nvkm_output_func *func, struct nvkm_disp *disp,
58 int index, struct dcb_output *dcbE, struct nvkm_output *outp)
59 {
60 struct nvkm_i2c *i2c = disp->engine.subdev.device->i2c;
61
62 outp->func = func;
63 outp->disp = disp;
64 outp->index = index;
65 outp->info = *dcbE;
66 outp->i2c = nvkm_i2c_bus_find(i2c, dcbE->i2c_index);
67 outp->or = ffs(outp->info.or) - 1;
68
69 OUTP_DBG(outp, "type %02x loc %d or %d link %d con %x "
70 "edid %x bus %d head %x",
71 outp->info.type, outp->info.location, outp->info.or,
72 outp->info.type >= 2 ? outp->info.sorconf.link : 0,
73 outp->info.connector, outp->info.i2c_index,
74 outp->info.bus, outp->info.heads);
75 }
76
77 int
nvkm_output_new_(const struct nvkm_output_func * func,struct nvkm_disp * disp,int index,struct dcb_output * dcbE,struct nvkm_output ** poutp)78 nvkm_output_new_(const struct nvkm_output_func *func,
79 struct nvkm_disp *disp, int index, struct dcb_output *dcbE,
80 struct nvkm_output **poutp)
81 {
82 if (!(*poutp = kzalloc(sizeof(**poutp), GFP_KERNEL)))
83 return -ENOMEM;
84
85 nvkm_output_ctor(func, disp, index, dcbE, *poutp);
86 return 0;
87 }
88