Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[cris-mirror.git] / drivers / gpu / drm / nouveau / nvkm / engine / disp / conn.c
blobfebc5c2744884413947b6501c8f3b52911d944ce
1 /*
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.
22 * Authors: Ben Skeggs
24 #include "conn.h"
25 #include "outp.h"
26 #include "priv.h"
28 #include <subdev/gpio.h>
30 #include <nvif/event.h>
32 static int
33 nvkm_conn_hpd(struct nvkm_notify *notify)
35 struct nvkm_conn *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;
46 else
47 rep.mask = NVIF_NOTIFY_CONN_V0_PLUG;
48 rep.version = 0;
50 nvkm_event_send(&disp->hpd, rep.mask, index, &rep, sizeof(rep));
51 return NVKM_NOTIFY_KEEP;
54 void
55 nvkm_conn_fini(struct nvkm_conn *conn)
57 nvkm_notify_put(&conn->hpd);
60 void
61 nvkm_conn_init(struct nvkm_conn *conn)
63 nvkm_notify_get(&conn->hpd);
66 void
67 nvkm_conn_del(struct nvkm_conn **pconn)
69 struct nvkm_conn *conn = *pconn;
70 if (conn) {
71 nvkm_notify_fini(&conn->hpd);
72 kfree(*pconn);
73 *pconn = NULL;
77 static void
78 nvkm_conn_ctor(struct nvkm_disp *disp, int index, struct nvbios_connE *info,
79 struct nvkm_conn *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;
84 int ret;
86 conn->disp = disp;
87 conn->index = index;
88 conn->info = *info;
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);
97 return;
99 info->hpd = hpd[info->hpd];
101 ret = nvkm_gpio_find(gpio, 0, info->hpd, DCB_GPIO_UNUSED, &func);
102 if (ret) {
103 CONN_ERR(conn, "func %02x lookup failed, %d",
104 info->hpd, ret);
105 return;
108 ret = nvkm_notify_init(NULL, &gpio->event, nvkm_conn_hpd,
109 true, &(struct nvkm_gpio_ntfy_req) {
110 .mask = NVKM_GPIO_TOGGLED,
111 .line = func.line,
113 sizeof(struct nvkm_gpio_ntfy_req),
114 sizeof(struct nvkm_gpio_ntfy_rep),
115 &conn->hpd);
116 if (ret) {
117 CONN_ERR(conn, "func %02x failed, %d", info->hpd, ret);
118 } else {
119 CONN_DBG(conn, "func %02x (HPD)", info->hpd);
125 nvkm_conn_new(struct nvkm_disp *disp, int index, struct nvbios_connE *info,
126 struct nvkm_conn **pconn)
128 if (!(*pconn = kzalloc(sizeof(**pconn), GFP_KERNEL)))
129 return -ENOMEM;
130 nvkm_conn_ctor(disp, index, info, *pconn);
131 return 0;