1c39f472eSBen Skeggs /*
2c39f472eSBen Skeggs * Copyright 2014 Red Hat Inc.
3c39f472eSBen Skeggs *
4c39f472eSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
5c39f472eSBen Skeggs * copy of this software and associated documentation files (the "Software"),
6c39f472eSBen Skeggs * to deal in the Software without restriction, including without limitation
7c39f472eSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8c39f472eSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
9c39f472eSBen Skeggs * Software is furnished to do so, subject to the following conditions:
10c39f472eSBen Skeggs *
11c39f472eSBen Skeggs * The above copyright notice and this permission notice shall be included in
12c39f472eSBen Skeggs * all copies or substantial portions of the Software.
13c39f472eSBen Skeggs *
14c39f472eSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c39f472eSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c39f472eSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17c39f472eSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18c39f472eSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19c39f472eSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20c39f472eSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
21c39f472eSBen Skeggs *
22c39f472eSBen Skeggs * Authors: Ben Skeggs
23c39f472eSBen Skeggs */
24878da15aSBen Skeggs #include "conn.h"
25878da15aSBen Skeggs #include "outp.h"
26878da15aSBen Skeggs #include "priv.h"
27c39f472eSBen Skeggs
28c39f472eSBen Skeggs #include <subdev/gpio.h>
29c39f472eSBen Skeggs
30878da15aSBen Skeggs #include <nvif/event.h>
31c39f472eSBen Skeggs
32f2c906fcSBen Skeggs void
nvkm_conn_del(struct nvkm_conn ** pconn)33981a8162SBen Skeggs nvkm_conn_del(struct nvkm_conn **pconn)
34f2c906fcSBen Skeggs {
35981a8162SBen Skeggs struct nvkm_conn *conn = *pconn;
36f2c906fcSBen Skeggs if (conn) {
37f2c906fcSBen Skeggs kfree(*pconn);
38f2c906fcSBen Skeggs *pconn = NULL;
39f2c906fcSBen Skeggs }
40f2c906fcSBen Skeggs }
41f2c906fcSBen Skeggs
42f2c906fcSBen Skeggs static void
nvkm_conn_ctor(struct nvkm_disp * disp,int index,struct nvbios_connE * info,struct nvkm_conn * conn)43981a8162SBen Skeggs nvkm_conn_ctor(struct nvkm_disp *disp, int index, struct nvbios_connE *info,
44981a8162SBen Skeggs struct nvkm_conn *conn)
45c39f472eSBen Skeggs {
46c39f472eSBen Skeggs static const u8 hpd[] = { 0x07, 0x08, 0x51, 0x52, 0x5e, 0x5f, 0x60 };
47f2c906fcSBen Skeggs struct nvkm_gpio *gpio = disp->engine.subdev.device->gpio;
48c39f472eSBen Skeggs struct dcb_gpio_func func;
49c39f472eSBen Skeggs int ret;
50c39f472eSBen Skeggs
51f2c906fcSBen Skeggs conn->disp = disp;
52c39f472eSBen Skeggs conn->index = index;
53f2c906fcSBen Skeggs conn->info = *info;
54*32dd9236SBen Skeggs conn->info.hpd = DCB_GPIO_UNUSED;
55c39f472eSBen Skeggs
56f2c906fcSBen Skeggs CONN_DBG(conn, "type %02x loc %d hpd %02x dp %x di %x sr %x lcdid %x",
57c39f472eSBen Skeggs info->type, info->location, info->hpd, info->dp,
58c39f472eSBen Skeggs info->di, info->sr, info->lcdid);
59c39f472eSBen Skeggs
60c39f472eSBen Skeggs if ((info->hpd = ffs(info->hpd))) {
61c39f472eSBen Skeggs if (--info->hpd >= ARRAY_SIZE(hpd)) {
62f2c906fcSBen Skeggs CONN_ERR(conn, "hpd %02x unknown", info->hpd);
63f2c906fcSBen Skeggs return;
64c39f472eSBen Skeggs }
65c39f472eSBen Skeggs info->hpd = hpd[info->hpd];
66c39f472eSBen Skeggs
672ea7249fSBen Skeggs ret = nvkm_gpio_find(gpio, 0, info->hpd, DCB_GPIO_UNUSED, &func);
68c39f472eSBen Skeggs if (ret) {
69*32dd9236SBen Skeggs CONN_ERR(conn, "func %02x lookup failed, %d", info->hpd, ret);
70f2c906fcSBen Skeggs return;
71c39f472eSBen Skeggs }
72c39f472eSBen Skeggs
73*32dd9236SBen Skeggs conn->info.hpd = func.line;
74c39f472eSBen Skeggs }
75c39f472eSBen Skeggs }
76c39f472eSBen Skeggs
77c39f472eSBen Skeggs int
nvkm_conn_new(struct nvkm_disp * disp,int index,struct nvbios_connE * info,struct nvkm_conn ** pconn)78981a8162SBen Skeggs nvkm_conn_new(struct nvkm_disp *disp, int index, struct nvbios_connE *info,
79981a8162SBen Skeggs struct nvkm_conn **pconn)
80c39f472eSBen Skeggs {
81f2c906fcSBen Skeggs if (!(*pconn = kzalloc(sizeof(**pconn), GFP_KERNEL)))
82f2c906fcSBen Skeggs return -ENOMEM;
83981a8162SBen Skeggs nvkm_conn_ctor(disp, index, info, *pconn);
84c39f472eSBen Skeggs return 0;
85c39f472eSBen Skeggs }
86