2 * Copyright 2021 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.
22 #define nvkm_uconn(p) container_of((p), struct nvkm_conn, object)
26 #include <core/client.h>
27 #include <core/event.h>
28 #include <subdev/gpio.h>
29 #include <subdev/i2c.h>
31 #include <nvif/if0011.h>
34 nvkm_uconn_uevent_aux(struct nvkm_object *object, u64 token, u32 bits)
36 union nvif_conn_event_args args;
40 if (bits & NVKM_I2C_PLUG)
41 args.v0.types |= NVIF_CONN_EVENT_V0_PLUG;
42 if (bits & NVKM_I2C_UNPLUG)
43 args.v0.types |= NVIF_CONN_EVENT_V0_UNPLUG;
44 if (bits & NVKM_I2C_IRQ)
45 args.v0.types |= NVIF_CONN_EVENT_V0_IRQ;
47 return object->client->event(token, &args, sizeof(args.v0));
51 nvkm_uconn_uevent_gpio(struct nvkm_object *object, u64 token, u32 bits)
53 union nvif_conn_event_args args;
57 if (bits & NVKM_GPIO_HI)
58 args.v0.types |= NVIF_CONN_EVENT_V0_PLUG;
59 if (bits & NVKM_GPIO_LO)
60 args.v0.types |= NVIF_CONN_EVENT_V0_UNPLUG;
62 return object->client->event(token, &args, sizeof(args.v0));
66 nvkm_uconn_uevent(struct nvkm_object *object, void *argv, u32 argc, struct nvkm_uevent *uevent)
68 struct nvkm_conn *conn = nvkm_uconn(object);
69 struct nvkm_device *device = conn->disp->engine.subdev.device;
70 struct nvkm_outp *outp;
71 union nvif_conn_event_args *args = argv;
75 if (conn->info.hpd == DCB_GPIO_UNUSED)
80 if (argc != sizeof(args->v0) || args->v0.version != 0)
83 list_for_each_entry(outp, &conn->disp->outps, head) {
84 if (outp->info.connector == conn->index)
88 if (&outp->head == &conn->disp->outps)
91 if (outp->dp.aux && !outp->info.location) {
92 if (args->v0.types & NVIF_CONN_EVENT_V0_PLUG ) bits |= NVKM_I2C_PLUG;
93 if (args->v0.types & NVIF_CONN_EVENT_V0_UNPLUG) bits |= NVKM_I2C_UNPLUG;
94 if (args->v0.types & NVIF_CONN_EVENT_V0_IRQ ) bits |= NVKM_I2C_IRQ;
96 return nvkm_uevent_add(uevent, &device->i2c->event, outp->dp.aux->id, bits,
97 nvkm_uconn_uevent_aux);
100 if (args->v0.types & NVIF_CONN_EVENT_V0_PLUG ) bits |= NVKM_GPIO_HI;
101 if (args->v0.types & NVIF_CONN_EVENT_V0_UNPLUG) bits |= NVKM_GPIO_LO;
102 if (args->v0.types & NVIF_CONN_EVENT_V0_IRQ) {
103 /* TODO: support DP IRQ on ANX9805 and remove this hack. */
104 if (!outp->info.location)
108 return nvkm_uevent_add(uevent, &device->gpio->event, conn->info.hpd, bits,
109 nvkm_uconn_uevent_gpio);
113 nvkm_uconn_dtor(struct nvkm_object *object)
115 struct nvkm_conn *conn = nvkm_uconn(object);
116 struct nvkm_disp *disp = conn->disp;
118 spin_lock(&disp->client.lock);
119 conn->object.func = NULL;
120 spin_unlock(&disp->client.lock);
124 static const struct nvkm_object_func
126 .dtor = nvkm_uconn_dtor,
127 .uevent = nvkm_uconn_uevent,
131 nvkm_uconn_new(const struct nvkm_oclass *oclass, void *argv, u32 argc, struct nvkm_object **pobject)
133 struct nvkm_disp *disp = nvkm_udisp(oclass->parent);
134 struct nvkm_conn *cont, *conn = NULL;
135 union nvif_conn_args *args = argv;
138 if (argc != sizeof(args->v0) || args->v0.version != 0)
141 list_for_each_entry(cont, &disp->conns, head) {
142 if (cont->index == args->v0.id) {
152 spin_lock(&disp->client.lock);
153 if (!conn->object.func) {
154 switch (conn->info.type) {
155 case DCB_CONNECTOR_VGA : args->v0.type = NVIF_CONN_V0_VGA; break;
156 case DCB_CONNECTOR_TV_0 :
157 case DCB_CONNECTOR_TV_1 :
158 case DCB_CONNECTOR_TV_3 : args->v0.type = NVIF_CONN_V0_TV; break;
159 case DCB_CONNECTOR_DMS59_0 :
160 case DCB_CONNECTOR_DMS59_1 :
161 case DCB_CONNECTOR_DVI_I : args->v0.type = NVIF_CONN_V0_DVI_I; break;
162 case DCB_CONNECTOR_DVI_D : args->v0.type = NVIF_CONN_V0_DVI_D; break;
163 case DCB_CONNECTOR_LVDS : args->v0.type = NVIF_CONN_V0_LVDS; break;
164 case DCB_CONNECTOR_LVDS_SPWG: args->v0.type = NVIF_CONN_V0_LVDS_SPWG; break;
165 case DCB_CONNECTOR_DMS59_DP0:
166 case DCB_CONNECTOR_DMS59_DP1:
167 case DCB_CONNECTOR_DP :
168 case DCB_CONNECTOR_mDP :
169 case DCB_CONNECTOR_USB_C : args->v0.type = NVIF_CONN_V0_DP; break;
170 case DCB_CONNECTOR_eDP : args->v0.type = NVIF_CONN_V0_EDP; break;
171 case DCB_CONNECTOR_HDMI_0 :
172 case DCB_CONNECTOR_HDMI_1 :
173 case DCB_CONNECTOR_HDMI_C : args->v0.type = NVIF_CONN_V0_HDMI; break;
180 nvkm_object_ctor(&nvkm_uconn, oclass, &conn->object);
181 *pobject = &conn->object;
184 spin_unlock(&disp->client.lock);