2 * Copyright 2012 Red Hat Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
26 #include <core/class.h>
28 #include <subdev/bios.h>
29 #include <subdev/bios/dcb.h>
30 #include <subdev/bios/dp.h>
31 #include <subdev/bios/init.h>
32 #include <subdev/timer.h>
38 nv94_sor_soff(struct nvkm_output_dp *outp)
40 return (ffs(outp->base.info.or) - 1) * 0x800;
44 nv94_sor_loff(struct nvkm_output_dp *outp)
46 return nv94_sor_soff(outp) + !(outp->base.info.sorconf.link & 1) * 0x80;
50 nv94_sor_dp_lane_map(struct nv50_disp_priv *priv, u8 lane)
52 static const u8 nvaf[] = { 24, 16, 8, 0 }; /* thanks, apple.. */
53 static const u8 nv94[] = { 16, 8, 0, 24 };
54 if (nv_device(priv)->chipset == 0xaf)
60 nv94_sor_dp_pattern(struct nvkm_output_dp *outp, int pattern)
62 struct nv50_disp_priv *priv = (void *)nouveau_disp(outp);
63 const u32 loff = nv94_sor_loff(outp);
64 nv_mask(priv, 0x61c10c + loff, 0x0f000000, pattern << 24);
69 nv94_sor_dp_lnk_pwr(struct nvkm_output_dp *outp, int nr)
71 struct nv50_disp_priv *priv = (void *)nouveau_disp(outp);
72 const u32 soff = nv94_sor_soff(outp);
73 const u32 loff = nv94_sor_loff(outp);
76 for (i = 0; i < nr; i++)
77 mask |= 1 << (nv94_sor_dp_lane_map(priv, i) >> 3);
79 nv_mask(priv, 0x61c130 + loff, 0x0000000f, mask);
80 nv_mask(priv, 0x61c034 + soff, 0x80000000, 0x80000000);
81 nv_wait(priv, 0x61c034 + soff, 0x80000000, 0x00000000);
86 nv94_sor_dp_lnk_ctl(struct nvkm_output_dp *outp, int nr, int bw, bool ef)
88 struct nv50_disp_priv *priv = (void *)nouveau_disp(outp);
89 const u32 soff = nv94_sor_soff(outp);
90 const u32 loff = nv94_sor_loff(outp);
91 u32 dpctrl = 0x00000000;
92 u32 clksor = 0x00000000;
94 dpctrl |= ((1 << nr) - 1) << 16;
100 nv_mask(priv, 0x614300 + soff, 0x000c0000, clksor);
101 nv_mask(priv, 0x61c10c + loff, 0x001f4000, dpctrl);
106 nv94_sor_dp_drv_ctl(struct nvkm_output_dp *outp, int ln, int vs, int pe, int pc)
108 struct nv50_disp_priv *priv = (void *)nouveau_disp(outp);
109 struct nouveau_bios *bios = nouveau_bios(priv);
110 const u32 shift = nv94_sor_dp_lane_map(priv, ln);
111 const u32 loff = nv94_sor_loff(outp);
113 u8 ver, hdr, cnt, len;
114 struct nvbios_dpout info;
115 struct nvbios_dpcfg ocfg;
117 addr = nvbios_dpout_match(bios, outp->base.info.hasht,
118 outp->base.info.hashm,
119 &ver, &hdr, &cnt, &len, &info);
123 addr = nvbios_dpcfg_match(bios, addr, 0, vs, pe,
124 &ver, &hdr, &cnt, &len, &ocfg);
128 data[0] = nv_rd32(priv, 0x61c118 + loff) & ~(0x000000ff << shift);
129 data[1] = nv_rd32(priv, 0x61c120 + loff) & ~(0x000000ff << shift);
130 data[2] = nv_rd32(priv, 0x61c130 + loff);
131 if ((data[2] & 0x0000ff00) < (ocfg.tx_pu << 8) || ln == 0)
132 data[2] = (data[2] & ~0x0000ff00) | (ocfg.tx_pu << 8);
133 nv_wr32(priv, 0x61c118 + loff, data[0] | (ocfg.dc << shift));
134 nv_wr32(priv, 0x61c120 + loff, data[1] | (ocfg.pe << shift));
135 nv_wr32(priv, 0x61c130 + loff, data[2] | (ocfg.tx_pu << 8));
139 struct nvkm_output_dp_impl
141 .base.base.handle = DCB_OUTPUT_DP,
142 .base.base.ofuncs = &(struct nouveau_ofuncs) {
143 .ctor = _nvkm_output_dp_ctor,
144 .dtor = _nvkm_output_dp_dtor,
145 .init = _nvkm_output_dp_init,
146 .fini = _nvkm_output_dp_fini,
148 .pattern = nv94_sor_dp_pattern,
149 .lnk_pwr = nv94_sor_dp_lnk_pwr,
150 .lnk_ctl = nv94_sor_dp_lnk_ctl,
151 .drv_ctl = nv94_sor_dp_drv_ctl,