summaryrefslogtreecommitdiffstats
path: root/kernel/drivers/gpu/drm/nouveau/nvkm/engine/disp/outp.c
blob: 9224bcbf015926b9343abb94c6a9552724fbadad (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
/*
 * 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
 */
#include "outp.h"
#include "priv.h"

#include <subdev/bios.h>
#include <subdev/bios/conn.h>
#include <subdev/bios/dcb.h>
#include <subdev/i2c.h>

int
_nvkm_output_fini(struct nvkm_object *object, bool suspend)
{
	struct nvkm_output *outp = (void *)object;
	nv_ofuncs(outp->conn)->fini(nv_object(outp->conn), suspend);
	return nvkm_object_fini(&outp->base, suspend);
}

int
_nvkm_output_init(struct nvkm_object *object)
{
	struct nvkm_output *outp = (void *)object;
	int ret = nvkm_object_init(&outp->base);
	if (ret == 0)
		nv_ofuncs(outp->conn)->init(nv_object(outp->conn));
	return 0;
}

void
_nvkm_output_dtor(struct nvkm_object *object)
{
	struct nvkm_output *outp = (void *)object;
	list_del(&outp->head);
	nvkm_object_ref(NULL, (void *)&outp->conn);
	nvkm_object_destroy(&outp->base);
}

int
nvkm_output_create_(struct nvkm_object *parent,
		    struct nvkm_object *engine,
		    struct nvkm_oclass *oclass,
		    struct dcb_output *dcbE, int index,
		    int length, void **pobject)
{
	struct nvkm_disp *disp = nvkm_disp(parent);
	struct nvkm_bios *bios = nvkm_bios(parent);
	struct nvkm_i2c *i2c = nvkm_i2c(parent);
	struct nvbios_connE connE;
	struct nvkm_output *outp;
	u8  ver, hdr;
	u32 data;
	int ret;

	ret = nvkm_object_create_(parent, engine, oclass, 0, length, pobject);
	outp = *pobject;
	if (ret)
		return ret;

	outp->info = *dcbE;
	outp->index = index;
	outp->or = ffs(outp->info.or) - 1;

	DBG("type %02x loc %d or %d link %d con %x edid %x bus %d head %x\n",
	    dcbE->type, dcbE->location, dcbE->or, dcbE->type >= 2 ?
	    dcbE->sorconf.link : 0, dcbE->connector, dcbE->i2c_index,
	    dcbE->bus, dcbE->heads);

	if (outp->info.type != DCB_OUTPUT_DP)
		outp->port = i2c->find(i2c, NV_I2C_PORT(outp->info.i2c_index));
	else
		outp->port = i2c->find(i2c, NV_I2C_AUX(outp->info.i2c_index));
	outp->edid = outp->port;

	data = nvbios_connEp(bios, outp->info.connector, &ver, &hdr, &connE);
	if (!data) {
		DBG("vbios connector data not found\n");
		memset(&connE, 0x00, sizeof(connE));
		connE.type = DCB_CONNECTOR_NONE;
	}

	ret = nvkm_object_ctor(parent, NULL, nvkm_connector_oclass,
			       &connE, outp->info.connector,
			       (struct nvkm_object **)&outp->conn);
	if (ret < 0) {
		ERR("error %d creating connector, disabling\n", ret);
		return ret;
	}

	list_add_tail(&outp->head, &disp->outp);
	return 0;
}

int
_nvkm_output_ctor(struct nvkm_object *parent,
		  struct nvkm_object *engine,
		  struct nvkm_oclass *oclass, void *dcbE, u32 index,
		  struct nvkm_object **pobject)
{
	struct nvkm_output *outp;
	int ret;

	ret = nvkm_output_create(parent, engine, oclass, dcbE, index, &outp);
	*pobject = nv_object(outp);
	if (ret)
		return ret;

	return 0;
}

struct nvkm_oclass *
nvkm_output_oclass = &(struct nvkm_output_impl) {
	.base = {
		.handle = 0,
		.ofuncs = &(struct nvkm_ofuncs) {
			.ctor = _nvkm_output_ctor,
			.dtor = _nvkm_output_dtor,
			.init = _nvkm_output_init,
			.fini = _nvkm_output_fini,
		},
	},
}.base;