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>
36 nv94_sor_dp_lane_map(struct nv50_disp_priv *priv, u8 lane)
38 static const u8 nvaf[] = { 24, 16, 8, 0 }; /* thanks, apple.. */
39 static const u8 nv94[] = { 16, 8, 0, 24 };
40 if (nv_device(priv)->chipset == 0xaf)
46 nv94_sor_dp_train_init(struct nv50_disp_priv *priv, int or, int link, int head,
47 u16 type, u16 mask, u32 data, struct dcb_output *dcbo)
49 struct nouveau_bios *bios = nouveau_bios(priv);
50 struct nvbios_dpout info;
51 u8 ver, hdr, cnt, len;
54 outp = nvbios_dpout_match(bios, type, mask, &ver, &hdr, &cnt, &len, &info);
56 struct nvbios_init init = {
57 .subdev = nv_subdev(priv),
64 if (data & NV94_DISP_SOR_DP_TRAIN_INIT_SPREAD_ON)
65 init.offset = info.script[2];
67 init.offset = info.script[3];
70 init.offset = info.script[0];
78 nv94_sor_dp_train_fini(struct nv50_disp_priv *priv, int or, int link, int head,
79 u16 type, u16 mask, u32 data, struct dcb_output *dcbo)
81 struct nouveau_bios *bios = nouveau_bios(priv);
82 struct nvbios_dpout info;
83 u8 ver, hdr, cnt, len;
86 outp = nvbios_dpout_match(bios, type, mask, &ver, &hdr, &cnt, &len, &info);
88 struct nvbios_init init = {
89 .subdev = nv_subdev(priv),
91 .offset = info.script[1],
104 nv94_sor_dp_train(struct nv50_disp_priv *priv, int or, int link,
105 u16 type, u16 mask, u32 data, struct dcb_output *info)
107 const u32 loff = (or * 0x800) + (link * 0x80);
108 const u32 patt = (data & NV94_DISP_SOR_DP_TRAIN_PATTERN);
109 nv_mask(priv, 0x61c10c + loff, 0x0f000000, patt << 24);
114 nv94_sor_dp_lnkctl(struct nv50_disp_priv *priv, int or, int link, int head,
115 u16 type, u16 mask, u32 data, struct dcb_output *dcbo)
117 struct nouveau_bios *bios = nouveau_bios(priv);
118 const u32 loff = (or * 0x800) + (link * 0x80);
119 const u32 soff = (or * 0x800);
120 u16 link_bw = (data & NV94_DISP_SOR_DP_LNKCTL_WIDTH) >> 8;
121 u8 link_nr = (data & NV94_DISP_SOR_DP_LNKCTL_COUNT);
122 u32 dpctrl = 0x00000000;
123 u32 clksor = 0x00000000;
125 u8 ver, hdr, cnt, len;
126 struct nvbios_dpout info;
132 outp = nvbios_dpout_match(bios, type, mask, &ver, &hdr, &cnt, &len, &info);
133 if (outp && info.lnkcmp) {
134 struct nvbios_init init = {
135 .subdev = nv_subdev(priv),
143 while (link_bw < nv_ro16(bios, info.lnkcmp))
145 init.offset = nv_ro16(bios, info.lnkcmp + 2);
150 dpctrl |= ((1 << link_nr) - 1) << 16;
151 if (data & NV94_DISP_SOR_DP_LNKCTL_FRAME_ENH)
152 dpctrl |= 0x00004000;
154 clksor |= 0x00040000;
156 for (i = 0; i < link_nr; i++)
157 lane |= 1 << (nv94_sor_dp_lane_map(priv, i) >> 3);
159 nv_mask(priv, 0x614300 + soff, 0x000c0000, clksor);
160 nv_mask(priv, 0x61c10c + loff, 0x001f4000, dpctrl);
161 nv_mask(priv, 0x61c130 + loff, 0x0000000f, lane);
166 nv94_sor_dp_drvctl(struct nv50_disp_priv *priv, int or, int link, int lane,
167 u16 type, u16 mask, u32 data, struct dcb_output *dcbo)
169 struct nouveau_bios *bios = nouveau_bios(priv);
170 const u32 loff = (or * 0x800) + (link * 0x80);
171 const u8 swing = (data & NV94_DISP_SOR_DP_DRVCTL_VS) >> 8;
172 const u8 preem = (data & NV94_DISP_SOR_DP_DRVCTL_PE);
173 u32 addr, shift = nv94_sor_dp_lane_map(priv, lane);
174 u8 ver, hdr, cnt, len;
175 struct nvbios_dpout outp;
176 struct nvbios_dpcfg ocfg;
178 addr = nvbios_dpout_match(bios, type, mask, &ver, &hdr, &cnt, &len, &outp);
182 addr = nvbios_dpcfg_match(bios, addr, 0, swing, preem, &ver, &hdr, &cnt, &len, &ocfg);
186 nv_mask(priv, 0x61c118 + loff, 0x000000ff << shift, ocfg.drv << shift);
187 nv_mask(priv, 0x61c120 + loff, 0x000000ff << shift, ocfg.pre << shift);
188 nv_mask(priv, 0x61c130 + loff, 0x0000ff00, ocfg.unk << 8);