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.
28 #include <subdev/gpio.h>
30 #include <nvif/event.h>
33 nvkm_connector_hpd(struct nvkm_notify *notify)
35 struct nvkm_connector *conn = container_of(notify, typeof(*conn), hpd);
36 struct nvkm_disp *disp = nvkm_disp(conn);
37 struct nvkm_gpio *gpio = nvkm_gpio(conn);
38 const struct nvkm_gpio_ntfy_rep *line = notify->data;
39 struct nvif_notify_conn_rep_v0 rep;
40 int index = conn->index;
42 DBG("HPD: %d\n", line->mask);
44 if (!gpio->get(gpio, 0, DCB_GPIO_UNUSED, conn->hpd.index))
45 rep.mask = NVIF_NOTIFY_CONN_V0_UNPLUG;
47 rep.mask = NVIF_NOTIFY_CONN_V0_PLUG;
50 nvkm_event_send(&disp->hpd, rep.mask, index, &rep, sizeof(rep));
51 return NVKM_NOTIFY_KEEP;
55 _nvkm_connector_fini(struct nvkm_object *object, bool suspend)
57 struct nvkm_connector *conn = (void *)object;
58 nvkm_notify_put(&conn->hpd);
59 return nvkm_object_fini(&conn->base, suspend);
63 _nvkm_connector_init(struct nvkm_object *object)
65 struct nvkm_connector *conn = (void *)object;
66 int ret = nvkm_object_init(&conn->base);
68 nvkm_notify_get(&conn->hpd);
73 _nvkm_connector_dtor(struct nvkm_object *object)
75 struct nvkm_connector *conn = (void *)object;
76 nvkm_notify_fini(&conn->hpd);
77 nvkm_object_destroy(&conn->base);
81 nvkm_connector_create_(struct nvkm_object *parent,
82 struct nvkm_object *engine,
83 struct nvkm_oclass *oclass,
84 struct nvbios_connE *info, int index,
85 int length, void **pobject)
87 static const u8 hpd[] = { 0x07, 0x08, 0x51, 0x52, 0x5e, 0x5f, 0x60 };
88 struct nvkm_disp *disp = nvkm_disp(parent);
89 struct nvkm_gpio *gpio = nvkm_gpio(parent);
90 struct nvkm_connector *conn;
91 struct nvkm_output *outp;
92 struct dcb_gpio_func func;
95 list_for_each_entry(outp, &disp->outp, head) {
96 if (outp->conn && outp->conn->index == index) {
97 atomic_inc(&nv_object(outp->conn)->refcount);
98 *pobject = outp->conn;
103 ret = nvkm_object_create_(parent, engine, oclass, 0, length, pobject);
111 DBG("type %02x loc %d hpd %02x dp %x di %x sr %x lcdid %x\n",
112 info->type, info->location, info->hpd, info->dp,
113 info->di, info->sr, info->lcdid);
115 if ((info->hpd = ffs(info->hpd))) {
116 if (--info->hpd >= ARRAY_SIZE(hpd)) {
117 ERR("hpd %02x unknown\n", info->hpd);
120 info->hpd = hpd[info->hpd];
122 ret = gpio->find(gpio, 0, info->hpd, DCB_GPIO_UNUSED, &func);
124 ERR("func %02x lookup failed, %d\n", info->hpd, ret);
128 ret = nvkm_notify_init(NULL, &gpio->event, nvkm_connector_hpd,
129 true, &(struct nvkm_gpio_ntfy_req) {
130 .mask = NVKM_GPIO_TOGGLED,
133 sizeof(struct nvkm_gpio_ntfy_req),
134 sizeof(struct nvkm_gpio_ntfy_rep),
137 ERR("func %02x failed, %d\n", info->hpd, ret);
139 DBG("func %02x (HPD)\n", info->hpd);
147 _nvkm_connector_ctor(struct nvkm_object *parent,
148 struct nvkm_object *engine,
149 struct nvkm_oclass *oclass, void *info, u32 index,
150 struct nvkm_object **pobject)
152 struct nvkm_connector *conn;
155 ret = nvkm_connector_create(parent, engine, oclass, info, index, &conn);
156 *pobject = nv_object(conn);
164 nvkm_connector_oclass = &(struct nvkm_connector_impl) {
167 .ofuncs = &(struct nvkm_ofuncs) {
168 .ctor = _nvkm_connector_ctor,
169 .dtor = _nvkm_connector_dtor,
170 .init = _nvkm_connector_init,
171 .fini = _nvkm_connector_fini,