1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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>
32
33#include "nv50.h"
34
35static inline u32
36nvd0_sor_soff(struct dcb_output *outp)
37{
38 return (ffs(outp->or) - 1) * 0x800;
39}
40
41static inline u32
42nvd0_sor_loff(struct dcb_output *outp)
43{
44 return nvd0_sor_soff(outp) + !(outp->sorconf.link & 1) * 0x80;
45}
46
47static inline u32
48nvd0_sor_dp_lane_map(struct nv50_disp_priv *priv, u8 lane)
49{
50 static const u8 nvd0[] = { 16, 8, 0, 24 };
51 return nvd0[lane];
52}
53
54static int
55nvd0_sor_dp_pattern(struct nouveau_disp *disp, struct dcb_output *outp,
56 int head, int pattern)
57{
58 struct nv50_disp_priv *priv = (void *)disp;
59 const u32 loff = nvd0_sor_loff(outp);
60 nv_mask(priv, 0x61c110 + loff, 0x0f0f0f0f, 0x01010101 * pattern);
61 return 0;
62}
63
64static int
65nvd0_sor_dp_lnk_ctl(struct nouveau_disp *disp, struct dcb_output *outp,
66 int head, int link_nr, int link_bw, bool enh_frame)
67{
68 struct nv50_disp_priv *priv = (void *)disp;
69 const u32 soff = nvd0_sor_soff(outp);
70 const u32 loff = nvd0_sor_loff(outp);
71 u32 dpctrl = 0x00000000;
72 u32 clksor = 0x00000000;
73 u32 lane = 0;
74 int i;
75
76 clksor |= link_bw << 18;
77 dpctrl |= ((1 << link_nr) - 1) << 16;
78 if (enh_frame)
79 dpctrl |= 0x00004000;
80
81 for (i = 0; i < link_nr; i++)
82 lane |= 1 << (nvd0_sor_dp_lane_map(priv, i) >> 3);
83
84 nv_mask(priv, 0x612300 + soff, 0x007c0000, clksor);
85 nv_mask(priv, 0x61c10c + loff, 0x001f4000, dpctrl);
86 nv_mask(priv, 0x61c130 + loff, 0x0000000f, lane);
87 return 0;
88}
89
90static int
91nvd0_sor_dp_drv_ctl(struct nouveau_disp *disp, struct dcb_output *outp,
92 int head, int lane, int swing, int preem)
93{
94 struct nouveau_bios *bios = nouveau_bios(disp);
95 struct nv50_disp_priv *priv = (void *)disp;
96 const u32 loff = nvd0_sor_loff(outp);
97 u32 addr, shift = nvd0_sor_dp_lane_map(priv, lane);
98 u8 ver, hdr, cnt, len;
99 struct nvbios_dpout info;
100 struct nvbios_dpcfg ocfg;
101
102 addr = nvbios_dpout_match(bios, outp->hasht, outp->hashm,
103 &ver, &hdr, &cnt, &len, &info);
104 if (!addr)
105 return -ENODEV;
106
107 addr = nvbios_dpcfg_match(bios, addr, 0, swing, preem,
108 &ver, &hdr, &cnt, &len, &ocfg);
109 if (!addr)
110 return -EINVAL;
111
112 nv_mask(priv, 0x61c118 + loff, 0x000000ff << shift, ocfg.drv << shift);
113 nv_mask(priv, 0x61c120 + loff, 0x000000ff << shift, ocfg.pre << shift);
114 nv_mask(priv, 0x61c130 + loff, 0x0000ff00, ocfg.unk << 8);
115 nv_mask(priv, 0x61c13c + loff, 0x00000000, 0x00000000);
116 return 0;
117}
118
119const struct nouveau_dp_func
120nvd0_sor_dp_func = {
121 .pattern = nvd0_sor_dp_pattern,
122 .lnk_ctl = nvd0_sor_dp_lnk_ctl,
123 .drv_ctl = nvd0_sor_dp_drv_ctl,
124};
125