[go: nahoru, domu]

1/*
2 * Copyright 2012 Red Hat Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#include <core/client.h>
26#include <nvif/unpack.h>
27#include <nvif/class.h>
28
29#include <subdev/bios.h>
30#include <subdev/bios/dcb.h>
31#include <subdev/timer.h>
32#include <subdev/i2c.h>
33
34#include "nv50.h"
35
36/******************************************************************************
37 * TMDS
38 *****************************************************************************/
39
40static int
41nv50_pior_tmds_ctor(struct nouveau_object *parent,
42		    struct nouveau_object *engine,
43		    struct nouveau_oclass *oclass, void *info, u32 index,
44		    struct nouveau_object **pobject)
45{
46	struct nouveau_i2c *i2c = nouveau_i2c(parent);
47	struct nvkm_output *outp;
48	int ret;
49
50	ret = nvkm_output_create(parent, engine, oclass, info, index, &outp);
51	*pobject = nv_object(outp);
52	if (ret)
53		return ret;
54
55	outp->edid = i2c->find_type(i2c, NV_I2C_TYPE_EXTDDC(outp->info.extdev));
56	return 0;
57}
58
59struct nvkm_output_impl
60nv50_pior_tmds_impl = {
61	.base.handle = DCB_OUTPUT_TMDS | 0x0100,
62	.base.ofuncs = &(struct nouveau_ofuncs) {
63		.ctor = nv50_pior_tmds_ctor,
64		.dtor = _nvkm_output_dtor,
65		.init = _nvkm_output_init,
66		.fini = _nvkm_output_fini,
67	},
68};
69
70/******************************************************************************
71 * DisplayPort
72 *****************************************************************************/
73
74static int
75nv50_pior_dp_pattern(struct nvkm_output_dp *outp, int pattern)
76{
77	struct nouveau_i2c_port *port = outp->base.edid;
78	if (port && port->func->pattern)
79		return port->func->pattern(port, pattern);
80	return port ? 0 : -ENODEV;
81}
82
83static int
84nv50_pior_dp_lnk_pwr(struct nvkm_output_dp *outp, int nr)
85{
86	return 0;
87}
88
89static int
90nv50_pior_dp_lnk_ctl(struct nvkm_output_dp *outp, int nr, int bw, bool ef)
91{
92	struct nouveau_i2c_port *port = outp->base.edid;
93	if (port && port->func->lnk_ctl)
94		return port->func->lnk_ctl(port, nr, bw, ef);
95	return port ? 0 : -ENODEV;
96}
97
98static int
99nv50_pior_dp_drv_ctl(struct nvkm_output_dp *outp, int ln, int vs, int pe, int pc)
100{
101	struct nouveau_i2c_port *port = outp->base.edid;
102	if (port && port->func->drv_ctl)
103		return port->func->drv_ctl(port, ln, vs, pe);
104	return port ? 0 : -ENODEV;
105}
106
107static int
108nv50_pior_dp_ctor(struct nouveau_object *parent,
109		  struct nouveau_object *engine,
110		  struct nouveau_oclass *oclass, void *info, u32 index,
111		  struct nouveau_object **pobject)
112{
113	struct nouveau_i2c *i2c = nouveau_i2c(parent);
114	struct nvkm_output_dp *outp;
115	int ret;
116
117	ret = nvkm_output_dp_create(parent, engine, oclass, info, index, &outp);
118	*pobject = nv_object(outp);
119	if (ret)
120		return ret;
121
122	outp->base.edid = i2c->find_type(i2c, NV_I2C_TYPE_EXTAUX(
123					 outp->base.info.extdev));
124	return 0;
125}
126
127struct nvkm_output_dp_impl
128nv50_pior_dp_impl = {
129	.base.base.handle = DCB_OUTPUT_DP | 0x0010,
130	.base.base.ofuncs = &(struct nouveau_ofuncs) {
131		.ctor = nv50_pior_dp_ctor,
132		.dtor = _nvkm_output_dp_dtor,
133		.init = _nvkm_output_dp_init,
134		.fini = _nvkm_output_dp_fini,
135	},
136	.pattern = nv50_pior_dp_pattern,
137	.lnk_pwr = nv50_pior_dp_lnk_pwr,
138	.lnk_ctl = nv50_pior_dp_lnk_ctl,
139	.drv_ctl = nv50_pior_dp_drv_ctl,
140};
141
142/******************************************************************************
143 * General PIOR handling
144 *****************************************************************************/
145
146int
147nv50_pior_power(NV50_DISP_MTHD_V1)
148{
149	const u32 soff = outp->or * 0x800;
150	union {
151		struct nv50_disp_pior_pwr_v0 v0;
152	} *args = data;
153	u32 ctrl, type;
154	int ret;
155
156	nv_ioctl(object, "disp pior pwr size %d\n", size);
157	if (nvif_unpack(args->v0, 0, 0, false)) {
158		nv_ioctl(object, "disp pior pwr vers %d state %d type %x\n",
159			 args->v0.version, args->v0.state, args->v0.type);
160		if (args->v0.type > 0x0f)
161			return -EINVAL;
162		ctrl = !!args->v0.state;
163		type = args->v0.type;
164	} else
165		return ret;
166
167	nv_wait(priv, 0x61e004 + soff, 0x80000000, 0x00000000);
168	nv_mask(priv, 0x61e004 + soff, 0x80000101, 0x80000000 | ctrl);
169	nv_wait(priv, 0x61e004 + soff, 0x80000000, 0x00000000);
170	priv->pior.type[outp->or] = type;
171	return 0;
172}
173