1/* $NetBSD: nouveau_engine_disp_piornv50.c,v 1.1.1.1 2014/08/06 12:36:24 riastradh Exp $ */
2
3/*
4 * Copyright 2012 Red Hat Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 *
24 * Authors: Ben Skeggs
25 */
26
27#include <sys/cdefs.h>
28__KERNEL_RCSID(0, "$NetBSD: nouveau_engine_disp_piornv50.c,v 1.1.1.1 2014/08/06 12:36:24 riastradh Exp $");
29
30#include <core/os.h>
31#include <core/class.h>
32
33#include <subdev/bios.h>
34#include <subdev/bios/dcb.h>
35#include <subdev/timer.h>
36#include <subdev/i2c.h>
37
38#include "nv50.h"
39
40/******************************************************************************
41 * DisplayPort
42 *****************************************************************************/
43static struct nouveau_i2c_port *
44nv50_pior_dp_find(struct nouveau_disp *disp, struct dcb_output *outp)
45{
46 struct nouveau_i2c *i2c = nouveau_i2c(disp);
47 return i2c->find_type(i2c, NV_I2C_TYPE_EXTAUX(outp->extdev));
48}
49
50static int
51nv50_pior_dp_pattern(struct nouveau_disp *disp, struct dcb_output *outp,
52 int head, int pattern)
53{
54 struct nouveau_i2c_port *port;
55 int ret = -EINVAL;
56
57 port = nv50_pior_dp_find(disp, outp);
58 if (port) {
59 if (port->func->pattern)
60 ret = port->func->pattern(port, pattern);
61 else
62 ret = 0;
63 }
64
65 return ret;
66}
67
68static int
69nv50_pior_dp_lnk_ctl(struct nouveau_disp *disp, struct dcb_output *outp,
70 int head, int lane_nr, int link_bw, bool enh)
71{
72 struct nouveau_i2c_port *port;
73 int ret = -EINVAL;
74
75 port = nv50_pior_dp_find(disp, outp);
76 if (port && port->func->lnk_ctl)
77 ret = port->func->lnk_ctl(port, lane_nr, link_bw, enh);
78
79 return ret;
80}
81
82static int
83nv50_pior_dp_drv_ctl(struct nouveau_disp *disp, struct dcb_output *outp,
84 int head, int lane, int vsw, int pre)
85{
86 struct nouveau_i2c_port *port;
87 int ret = -EINVAL;
88
89 port = nv50_pior_dp_find(disp, outp);
90 if (port) {
91 if (port->func->drv_ctl)
92 ret = port->func->drv_ctl(port, lane, vsw, pre);
93 else
94 ret = 0;
95 }
96
97 return ret;
98}
99
100const struct nouveau_dp_func
101nv50_pior_dp_func = {
102 .pattern = nv50_pior_dp_pattern,
103 .lnk_ctl = nv50_pior_dp_lnk_ctl,
104 .drv_ctl = nv50_pior_dp_drv_ctl,
105};
106
107/******************************************************************************
108 * General PIOR handling
109 *****************************************************************************/
110int
111nv50_pior_power(struct nv50_disp_priv *priv, int or, u32 data)
112{
113 const u32 stat = data & NV50_DISP_PIOR_PWR_STATE;
114 const u32 soff = (or * 0x800);
115 nv_wait(priv, 0x61e004 + soff, 0x80000000, 0x00000000);
116 nv_mask(priv, 0x61e004 + soff, 0x80000101, 0x80000000 | stat);
117 nv_wait(priv, 0x61e004 + soff, 0x80000000, 0x00000000);
118 return 0;
119}
120
121int
122nv50_pior_mthd(struct nouveau_object *object, u32 mthd, void *args, u32 size)
123{
124 struct nv50_disp_priv *priv = (void *)object->engine;
125 const u8 type = (mthd & NV50_DISP_PIOR_MTHD_TYPE) >> 12;
126 const u8 or = (mthd & NV50_DISP_PIOR_MTHD_OR);
127 u32 *data = args;
128 int ret;
129
130 if (size < sizeof(u32))
131 return -EINVAL;
132
133 mthd &= ~NV50_DISP_PIOR_MTHD_TYPE;
134 mthd &= ~NV50_DISP_PIOR_MTHD_OR;
135 switch (mthd) {
136 case NV50_DISP_PIOR_PWR:
137 ret = priv->pior.power(priv, or, data[0]);
138 priv->pior.type[or] = type;
139 break;
140 default:
141 return -EINVAL;
142 }
143
144 return ret;
145}
146