2014-05-16 12:36:15 +08:00
|
|
|
/*
|
|
|
|
* Copyright 2014 Red Hat Inc.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors: Ben Skeggs
|
|
|
|
*/
|
2015-01-14 13:24:57 +08:00
|
|
|
#include "conn.h"
|
|
|
|
#include "outp.h"
|
|
|
|
#include "priv.h"
|
2014-08-10 02:10:20 +08:00
|
|
|
|
2014-05-16 12:36:15 +08:00
|
|
|
#include <subdev/gpio.h>
|
|
|
|
|
2015-01-14 13:24:57 +08:00
|
|
|
#include <nvif/event.h>
|
2014-05-16 12:36:15 +08:00
|
|
|
|
2014-08-10 02:10:20 +08:00
|
|
|
static int
|
|
|
|
nvkm_connector_hpd(struct nvkm_notify *notify)
|
2014-05-16 12:36:15 +08:00
|
|
|
{
|
2014-08-10 02:10:20 +08:00
|
|
|
struct nvkm_connector *conn = container_of(notify, typeof(*conn), hpd);
|
2015-01-14 13:24:57 +08:00
|
|
|
struct nvkm_disp *disp = nvkm_disp(conn);
|
|
|
|
struct nvkm_gpio *gpio = nvkm_gpio(conn);
|
2014-08-10 02:10:20 +08:00
|
|
|
const struct nvkm_gpio_ntfy_rep *line = notify->data;
|
|
|
|
struct nvif_notify_conn_rep_v0 rep;
|
|
|
|
int index = conn->index;
|
2014-05-16 12:36:15 +08:00
|
|
|
|
2014-08-10 02:10:20 +08:00
|
|
|
DBG("HPD: %d\n", line->mask);
|
|
|
|
|
|
|
|
if (!gpio->get(gpio, 0, DCB_GPIO_UNUSED, conn->hpd.index))
|
|
|
|
rep.mask = NVIF_NOTIFY_CONN_V0_UNPLUG;
|
|
|
|
else
|
|
|
|
rep.mask = NVIF_NOTIFY_CONN_V0_PLUG;
|
|
|
|
rep.version = 0;
|
|
|
|
|
|
|
|
nvkm_event_send(&disp->hpd, rep.mask, index, &rep, sizeof(rep));
|
|
|
|
return NVKM_NOTIFY_KEEP;
|
2014-05-16 12:36:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 13:24:57 +08:00
|
|
|
_nvkm_connector_fini(struct nvkm_object *object, bool suspend)
|
2014-05-16 12:36:15 +08:00
|
|
|
{
|
|
|
|
struct nvkm_connector *conn = (void *)object;
|
2014-08-10 02:10:20 +08:00
|
|
|
nvkm_notify_put(&conn->hpd);
|
2015-01-14 13:24:57 +08:00
|
|
|
return nvkm_object_fini(&conn->base, suspend);
|
2014-05-16 12:36:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 13:24:57 +08:00
|
|
|
_nvkm_connector_init(struct nvkm_object *object)
|
2014-05-16 12:36:15 +08:00
|
|
|
{
|
|
|
|
struct nvkm_connector *conn = (void *)object;
|
2015-01-14 13:24:57 +08:00
|
|
|
int ret = nvkm_object_init(&conn->base);
|
2014-08-10 02:10:20 +08:00
|
|
|
if (ret == 0)
|
|
|
|
nvkm_notify_get(&conn->hpd);
|
2014-05-16 12:36:15 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-01-14 13:24:57 +08:00
|
|
|
_nvkm_connector_dtor(struct nvkm_object *object)
|
2014-05-16 12:36:15 +08:00
|
|
|
{
|
|
|
|
struct nvkm_connector *conn = (void *)object;
|
2014-08-10 02:10:20 +08:00
|
|
|
nvkm_notify_fini(&conn->hpd);
|
2015-01-14 13:24:57 +08:00
|
|
|
nvkm_object_destroy(&conn->base);
|
2014-05-16 12:36:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 13:24:57 +08:00
|
|
|
nvkm_connector_create_(struct nvkm_object *parent,
|
|
|
|
struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass,
|
2014-05-16 12:36:15 +08:00
|
|
|
struct nvbios_connE *info, int index,
|
|
|
|
int length, void **pobject)
|
|
|
|
{
|
|
|
|
static const u8 hpd[] = { 0x07, 0x08, 0x51, 0x52, 0x5e, 0x5f, 0x60 };
|
2015-01-14 13:24:57 +08:00
|
|
|
struct nvkm_disp *disp = nvkm_disp(parent);
|
|
|
|
struct nvkm_gpio *gpio = nvkm_gpio(parent);
|
2014-05-16 12:36:15 +08:00
|
|
|
struct nvkm_connector *conn;
|
|
|
|
struct nvkm_output *outp;
|
|
|
|
struct dcb_gpio_func func;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
list_for_each_entry(outp, &disp->outp, head) {
|
|
|
|
if (outp->conn && outp->conn->index == index) {
|
|
|
|
atomic_inc(&nv_object(outp->conn)->refcount);
|
|
|
|
*pobject = outp->conn;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-01-14 13:24:57 +08:00
|
|
|
ret = nvkm_object_create_(parent, engine, oclass, 0, length, pobject);
|
2014-05-16 12:36:15 +08:00
|
|
|
conn = *pobject;
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
conn->info = *info;
|
|
|
|
conn->index = index;
|
|
|
|
|
|
|
|
DBG("type %02x loc %d hpd %02x dp %x di %x sr %x lcdid %x\n",
|
|
|
|
info->type, info->location, info->hpd, info->dp,
|
|
|
|
info->di, info->sr, info->lcdid);
|
|
|
|
|
|
|
|
if ((info->hpd = ffs(info->hpd))) {
|
|
|
|
if (--info->hpd >= ARRAY_SIZE(hpd)) {
|
|
|
|
ERR("hpd %02x unknown\n", info->hpd);
|
2014-08-10 02:10:20 +08:00
|
|
|
return 0;
|
2014-05-16 12:36:15 +08:00
|
|
|
}
|
|
|
|
info->hpd = hpd[info->hpd];
|
|
|
|
|
|
|
|
ret = gpio->find(gpio, 0, info->hpd, DCB_GPIO_UNUSED, &func);
|
|
|
|
if (ret) {
|
|
|
|
ERR("func %02x lookup failed, %d\n", info->hpd, ret);
|
2014-08-10 02:10:20 +08:00
|
|
|
return 0;
|
2014-05-16 12:36:15 +08:00
|
|
|
}
|
|
|
|
|
2014-08-11 11:56:56 +08:00
|
|
|
ret = nvkm_notify_init(NULL, &gpio->event, nvkm_connector_hpd,
|
|
|
|
true, &(struct nvkm_gpio_ntfy_req) {
|
2014-08-10 02:10:20 +08:00
|
|
|
.mask = NVKM_GPIO_TOGGLED,
|
|
|
|
.line = func.line,
|
|
|
|
},
|
|
|
|
sizeof(struct nvkm_gpio_ntfy_req),
|
|
|
|
sizeof(struct nvkm_gpio_ntfy_rep),
|
|
|
|
&conn->hpd);
|
2014-05-16 12:36:15 +08:00
|
|
|
if (ret) {
|
|
|
|
ERR("func %02x failed, %d\n", info->hpd, ret);
|
|
|
|
} else {
|
|
|
|
DBG("func %02x (HPD)\n", info->hpd);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 13:24:57 +08:00
|
|
|
_nvkm_connector_ctor(struct nvkm_object *parent,
|
|
|
|
struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, void *info, u32 index,
|
|
|
|
struct nvkm_object **pobject)
|
2014-05-16 12:36:15 +08:00
|
|
|
{
|
|
|
|
struct nvkm_connector *conn;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = nvkm_connector_create(parent, engine, oclass, info, index, &conn);
|
|
|
|
*pobject = nv_object(conn);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-01-14 13:24:57 +08:00
|
|
|
struct nvkm_oclass *
|
2014-05-16 12:36:15 +08:00
|
|
|
nvkm_connector_oclass = &(struct nvkm_connector_impl) {
|
|
|
|
.base = {
|
|
|
|
.handle = 0,
|
2015-01-14 13:24:57 +08:00
|
|
|
.ofuncs = &(struct nvkm_ofuncs) {
|
2014-05-16 12:36:15 +08:00
|
|
|
.ctor = _nvkm_connector_ctor,
|
|
|
|
.dtor = _nvkm_connector_dtor,
|
|
|
|
.init = _nvkm_connector_init,
|
|
|
|
.fini = _nvkm_connector_fini,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}.base;
|