piornv50.c 4.9 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
/*
 * Copyright 2012 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
 */
24 25
#include "nv50.h"
#include "outpdp.h"
26

27
#include <core/client.h>
28
#include <subdev/i2c.h>
29
#include <subdev/timer.h>
30

31 32
#include <nvif/class.h>
#include <nvif/unpack.h>
33

34 35 36 37 38
/******************************************************************************
 * TMDS
 *****************************************************************************/

static int
39 40 41 42
nv50_pior_tmds_ctor(struct nvkm_object *parent,
		    struct nvkm_object *engine,
		    struct nvkm_oclass *oclass, void *info, u32 index,
		    struct nvkm_object **pobject)
43
{
44
	struct nvkm_i2c *i2c = nvkm_i2c(parent);
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
	struct nvkm_output *outp;
	int ret;

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

	outp->edid = i2c->find_type(i2c, NV_I2C_TYPE_EXTDDC(outp->info.extdev));
	return 0;
}

struct nvkm_output_impl
nv50_pior_tmds_impl = {
	.base.handle = DCB_OUTPUT_TMDS | 0x0100,
60
	.base.ofuncs = &(struct nvkm_ofuncs) {
61 62 63 64 65 66 67
		.ctor = nv50_pior_tmds_ctor,
		.dtor = _nvkm_output_dtor,
		.init = _nvkm_output_init,
		.fini = _nvkm_output_fini,
	},
};

68 69 70
/******************************************************************************
 * DisplayPort
 *****************************************************************************/
71

72
static int
73
nv50_pior_dp_pattern(struct nvkm_output_dp *outp, int pattern)
74
{
75
	struct nvkm_i2c_port *port = outp->base.edid;
76 77 78
	if (port && port->func->pattern)
		return port->func->pattern(port, pattern);
	return port ? 0 : -ENODEV;
79 80
}

81 82 83 84 85 86
static int
nv50_pior_dp_lnk_pwr(struct nvkm_output_dp *outp, int nr)
{
	return 0;
}

87
static int
88
nv50_pior_dp_lnk_ctl(struct nvkm_output_dp *outp, int nr, int bw, bool ef)
89
{
90
	struct nvkm_i2c_port *port = outp->base.edid;
91
	if (port && port->func->lnk_ctl)
92 93
		return port->func->lnk_ctl(port, nr, bw, ef);
	return port ? 0 : -ENODEV;
94 95 96
}

static int
97
nv50_pior_dp_drv_ctl(struct nvkm_output_dp *outp, int ln, int vs, int pe, int pc)
98
{
99
	struct nvkm_i2c_port *port = outp->base.edid;
100 101 102
	if (port && port->func->drv_ctl)
		return port->func->drv_ctl(port, ln, vs, pe);
	return port ? 0 : -ENODEV;
103 104
}

105
static int
106 107 108 109
nv50_pior_dp_ctor(struct nvkm_object *parent,
		  struct nvkm_object *engine,
		  struct nvkm_oclass *oclass, void *info, u32 index,
		  struct nvkm_object **pobject)
110
{
111
	struct nvkm_i2c *i2c = nvkm_i2c(parent);
112
	struct nvkm_output_dp *outp;
113 114
	int ret;

115
	ret = nvkm_output_dp_create(parent, engine, oclass, info, index, &outp);
116 117 118 119
	*pobject = nv_object(outp);
	if (ret)
		return ret;

120 121
	outp->base.edid = i2c->find_type(i2c, NV_I2C_TYPE_EXTAUX(
					 outp->base.info.extdev));
122 123 124
	return 0;
}

125
struct nvkm_output_dp_impl
126
nv50_pior_dp_impl = {
127
	.base.base.handle = DCB_OUTPUT_DP | 0x0010,
128
	.base.base.ofuncs = &(struct nvkm_ofuncs) {
129
		.ctor = nv50_pior_dp_ctor,
130 131 132
		.dtor = _nvkm_output_dp_dtor,
		.init = _nvkm_output_dp_init,
		.fini = _nvkm_output_dp_fini,
133
	},
134
	.pattern = nv50_pior_dp_pattern,
135
	.lnk_pwr = nv50_pior_dp_lnk_pwr,
136 137
	.lnk_ctl = nv50_pior_dp_lnk_ctl,
	.drv_ctl = nv50_pior_dp_drv_ctl,
138 139
};

140 141 142
/******************************************************************************
 * General PIOR handling
 *****************************************************************************/
143

144
int
145
nv50_pior_power(NV50_DISP_MTHD_V1)
146
{
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
	const u32 soff = outp->or * 0x800;
	union {
		struct nv50_disp_pior_pwr_v0 v0;
	} *args = data;
	u32 ctrl, type;
	int ret;

	nv_ioctl(object, "disp pior pwr size %d\n", size);
	if (nvif_unpack(args->v0, 0, 0, false)) {
		nv_ioctl(object, "disp pior pwr vers %d state %d type %x\n",
			 args->v0.version, args->v0.state, args->v0.type);
		if (args->v0.type > 0x0f)
			return -EINVAL;
		ctrl = !!args->v0.state;
		type = args->v0.type;
	} else
		return ret;

165
	nv_wait(priv, 0x61e004 + soff, 0x80000000, 0x00000000);
166
	nv_mask(priv, 0x61e004 + soff, 0x80000101, 0x80000000 | ctrl);
167
	nv_wait(priv, 0x61e004 + soff, 0x80000000, 0x00000000);
168
	priv->pior.type[outp->or] = type;
169 170
	return 0;
}