1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include "conn.h"
25#include "outp.h"
26#include "priv.h"
27
28#include <subdev/gpio.h>
29
30#include <nvif/event.h>
31
32static int
33nvkm_conn_hpd(struct nvkm_notify *notify)
34{
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;
41
42 CONN_DBG(conn, "HPD: %d", line->mask);
43
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;
49
50 nvkm_event_send(&disp->hpd, rep.mask, index, &rep, sizeof(rep));
51 return NVKM_NOTIFY_KEEP;
52}
53
54void
55nvkm_conn_fini(struct nvkm_conn *conn)
56{
57 nvkm_notify_put(&conn->hpd);
58}
59
60void
61nvkm_conn_init(struct nvkm_conn *conn)
62{
63 nvkm_notify_get(&conn->hpd);
64}
65
66void
67nvkm_conn_del(struct nvkm_conn **pconn)
68{
69 struct nvkm_conn *conn = *pconn;
70 if (conn) {
71 nvkm_notify_fini(&conn->hpd);
72 kfree(*pconn);
73 *pconn = NULL;
74 }
75}
76
77static void
78nvkm_conn_ctor(struct nvkm_disp *disp, int index, struct nvbios_connE *info,
79 struct nvkm_conn *conn)
80{
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;
85
86 conn->disp = disp;
87 conn->index = index;
88 conn->info = *info;
89
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);
93
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;
98 }
99 info->hpd = hpd[info->hpd];
100
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;
106 }
107
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,
112 },
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);
120 }
121 }
122}
123
124int
125nvkm_conn_new(struct nvkm_disp *disp, int index, struct nvbios_connE *info,
126 struct nvkm_conn **pconn)
127{
128 if (!(*pconn = kzalloc(sizeof(**pconn), GFP_KERNEL)))
129 return -ENOMEM;
130 nvkm_conn_ctor(disp, index, info, *pconn);
131 return 0;
132}
133