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 = conn->disp;
37 struct nvkm_gpio *gpio = disp->engine.subdev.device->gpio;
38 const struct nvkm_gpio_ntfy_rep *line = notify->data;
39 struct nvif_notify_conn_rep_v0 rep;
40 int index = conn->index;
42 CONN_DBG(conn, "HPD: %d", line->mask);
44 if (!nvkm_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_connector *conn)
57 nvkm_notify_put(&conn->hpd);
61 nvkm_connector_init(struct nvkm_connector *conn)
63 nvkm_notify_get(&conn->hpd);
67 nvkm_connector_del(struct nvkm_connector **pconn)
69 struct nvkm_connector *conn = *pconn;
71 nvkm_notify_fini(&conn->hpd);
78 nvkm_connector_ctor(struct nvkm_disp *disp, int index,
79 struct nvbios_connE *info, struct nvkm_connector *conn)
81 static const u8 hpd[] = { 0x07, 0x08, 0x51, 0x52, 0x5e, 0x5f, 0x60 };
82 struct nvkm_gpio *gpio = disp->engine.subdev.device->gpio;
83 struct dcb_gpio_func func;
90 CONN_DBG(conn, "type %02x loc %d hpd %02x dp %x di %x sr %x lcdid %x",
91 info->type, info->location, info->hpd, info->dp,
92 info->di, info->sr, info->lcdid);
94 if ((info->hpd = ffs(info->hpd))) {
95 if (--info->hpd >= ARRAY_SIZE(hpd)) {
96 CONN_ERR(conn, "hpd %02x unknown", info->hpd);
99 info->hpd = hpd[info->hpd];
101 ret = nvkm_gpio_find(gpio, 0, info->hpd, DCB_GPIO_UNUSED, &func);
103 CONN_ERR(conn, "func %02x lookup failed, %d",
108 ret = nvkm_notify_init(NULL, &gpio->event, nvkm_connector_hpd,
109 true, &(struct nvkm_gpio_ntfy_req) {
110 .mask = NVKM_GPIO_TOGGLED,
113 sizeof(struct nvkm_gpio_ntfy_req),
114 sizeof(struct nvkm_gpio_ntfy_rep),
117 CONN_ERR(conn, "func %02x failed, %d", info->hpd, ret);
119 CONN_DBG(conn, "func %02x (HPD)", info->hpd);
125 nvkm_connector_new(struct nvkm_disp *disp, int index,
126 struct nvbios_connE *info, struct nvkm_connector **pconn)
128 if (!(*pconn = kzalloc(sizeof(**pconn), GFP_KERNEL)))
130 nvkm_connector_ctor(disp, index, info, *pconn);