]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/gpu/drm/nouveau/core/engine/disp/sornvd0.c
drm/nouveau/bios/dp: parse lane postcursor data
[mirror_ubuntu-artful-kernel.git] / drivers / gpu / drm / nouveau / core / engine / disp / sornvd0.c
CommitLineData
6c5a0424
BS
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/os.h>
26#include <core/class.h>
27
28#include <subdev/bios.h>
29#include <subdev/bios/dcb.h>
30#include <subdev/bios/dp.h>
31#include <subdev/bios/init.h>
1ecee1cd 32#include <subdev/timer.h>
6c5a0424
BS
33
34#include "nv50.h"
35
0a0afd28 36static inline u32
3b52a1f9 37nvd0_sor_soff(struct nvkm_output_dp *outp)
0a0afd28 38{
3b52a1f9 39 return (ffs(outp->base.info.or) - 1) * 0x800;
0a0afd28
BS
40}
41
42static inline u32
3b52a1f9 43nvd0_sor_loff(struct nvkm_output_dp *outp)
0a0afd28 44{
3b52a1f9 45 return nvd0_sor_soff(outp) + !(outp->base.info.sorconf.link & 1) * 0x80;
0a0afd28
BS
46}
47
6c5a0424
BS
48static inline u32
49nvd0_sor_dp_lane_map(struct nv50_disp_priv *priv, u8 lane)
50{
51 static const u8 nvd0[] = { 16, 8, 0, 24 };
52 return nvd0[lane];
53}
54
0a0afd28 55static int
3b52a1f9 56nvd0_sor_dp_pattern(struct nvkm_output_dp *outp, int pattern)
6c5a0424 57{
3b52a1f9 58 struct nv50_disp_priv *priv = (void *)nouveau_disp(outp);
0a0afd28
BS
59 const u32 loff = nvd0_sor_loff(outp);
60 nv_mask(priv, 0x61c110 + loff, 0x0f0f0f0f, 0x01010101 * pattern);
6c5a0424
BS
61 return 0;
62}
63
0a0afd28 64static int
3b52a1f9 65nvd0_sor_dp_lnk_ctl(struct nvkm_output_dp *outp, int nr, int bw, bool ef)
6c5a0424 66{
3b52a1f9 67 struct nv50_disp_priv *priv = (void *)nouveau_disp(outp);
0a0afd28
BS
68 const u32 soff = nvd0_sor_soff(outp);
69 const u32 loff = nvd0_sor_loff(outp);
6c5a0424
BS
70 u32 dpctrl = 0x00000000;
71 u32 clksor = 0x00000000;
6c5a0424 72
3b52a1f9
BS
73 clksor |= bw << 18;
74 dpctrl |= ((1 << nr) - 1) << 16;
75 if (ef)
6c5a0424
BS
76 dpctrl |= 0x00004000;
77
6c5a0424
BS
78 nv_mask(priv, 0x612300 + soff, 0x007c0000, clksor);
79 nv_mask(priv, 0x61c10c + loff, 0x001f4000, dpctrl);
6c5a0424
BS
80 return 0;
81}
82
0a0afd28 83static int
3b52a1f9 84nvd0_sor_dp_drv_ctl(struct nvkm_output_dp *outp, int ln, int vs, int pe, int pc)
6c5a0424 85{
3b52a1f9
BS
86 struct nv50_disp_priv *priv = (void *)nouveau_disp(outp);
87 struct nouveau_bios *bios = nouveau_bios(priv);
88 const u32 shift = nvd0_sor_dp_lane_map(priv, ln);
0a0afd28 89 const u32 loff = nvd0_sor_loff(outp);
7a14bc78 90 u32 addr, data[4];
6c5a0424 91 u8 ver, hdr, cnt, len;
0a0afd28 92 struct nvbios_dpout info;
6c5a0424
BS
93 struct nvbios_dpcfg ocfg;
94
3b52a1f9
BS
95 addr = nvbios_dpout_match(bios, outp->base.info.hasht,
96 outp->base.info.hashm,
0a0afd28 97 &ver, &hdr, &cnt, &len, &info);
6c5a0424
BS
98 if (!addr)
99 return -ENODEV;
100
7a14bc78 101 addr = nvbios_dpcfg_match(bios, addr, pc, vs, pe,
0a0afd28 102 &ver, &hdr, &cnt, &len, &ocfg);
6c5a0424
BS
103 if (!addr)
104 return -EINVAL;
105
6d8d1631
BS
106 data[0] = nv_rd32(priv, 0x61c118 + loff) & ~(0x000000ff << shift);
107 data[1] = nv_rd32(priv, 0x61c120 + loff) & ~(0x000000ff << shift);
108 data[2] = nv_rd32(priv, 0x61c130 + loff) & ~(0x0000ff00);
7a14bc78
BS
109 nv_wr32(priv, 0x61c118 + loff, data[0] | (ocfg.dc << shift));
110 nv_wr32(priv, 0x61c120 + loff, data[1] | (ocfg.pe << shift));
111 nv_wr32(priv, 0x61c130 + loff, data[2] | (ocfg.tx_pu << 8));
112 data[3] = nv_rd32(priv, 0x61c13c + loff) & ~(0x000000ff << shift);
113 nv_wr32(priv, 0x61c13c + loff, data[3] | (ocfg.pc << shift));
6c5a0424
BS
114 return 0;
115}
0a0afd28 116
b8407c9e
BS
117struct nvkm_output_dp_impl
118nvd0_sor_dp_impl = {
119 .base.base.handle = DCB_OUTPUT_DP,
120 .base.base.ofuncs = &(struct nouveau_ofuncs) {
121 .ctor = _nvkm_output_dp_ctor,
122 .dtor = _nvkm_output_dp_dtor,
123 .init = _nvkm_output_dp_init,
124 .fini = _nvkm_output_dp_fini,
125 },
3b52a1f9 126 .pattern = nvd0_sor_dp_pattern,
1ecee1cd 127 .lnk_pwr = nv94_sor_dp_lnk_pwr,
3b52a1f9
BS
128 .lnk_ctl = nvd0_sor_dp_lnk_ctl,
129 .drv_ctl = nvd0_sor_dp_drv_ctl,
b8407c9e 130};