]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/nouveau/core/engine/disp/sornv94.c
drm/nouveau/dp: remove last bits of VBIOS parsing from DRM code
[karo-tx-linux.git] / drivers / gpu / drm / nouveau / core / engine / disp / sornv94.c
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>
32
33 #include "nv50.h"
34
35 static inline u32
36 nv94_sor_dp_lane_map(struct nv50_disp_priv *priv, u8 lane)
37 {
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)
41                 return nvaf[lane];
42         return nv94[lane];
43 }
44
45 int
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)
48 {
49         struct nouveau_bios *bios = nouveau_bios(priv);
50         struct nvbios_dpout info;
51         u8  ver, hdr, cnt, len;
52         u16 outp;
53
54         outp = nvbios_dpout_match(bios, type, mask, &ver, &hdr, &cnt, &len, &info);
55         if (outp) {
56                 struct nvbios_init init = {
57                         .subdev = nv_subdev(priv),
58                         .bios = bios,
59                         .outp = dcbo,
60                         .crtc = head,
61                         .execute = 1,
62                 };
63
64                 if (data & NV94_DISP_SOR_DP_TRAIN_INIT_SPREAD_ON)
65                         init.offset = info.script[2];
66                 else
67                         init.offset = info.script[3];
68                 nvbios_exec(&init);
69
70                 init.offset = info.script[0];
71                 nvbios_exec(&init);
72         }
73
74         return 0;
75 }
76
77 int
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)
80 {
81         struct nouveau_bios *bios = nouveau_bios(priv);
82         struct nvbios_dpout info;
83         u8  ver, hdr, cnt, len;
84         u16 outp;
85
86         outp = nvbios_dpout_match(bios, type, mask, &ver, &hdr, &cnt, &len, &info);
87         if (outp) {
88                 struct nvbios_init init = {
89                         .subdev = nv_subdev(priv),
90                         .bios = bios,
91                         .offset = info.script[1],
92                         .outp = dcbo,
93                         .crtc = head,
94                         .execute = 1,
95                 };
96
97                 nvbios_exec(&init);
98         }
99
100         return 0;
101 }
102
103 int
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)
106 {
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);
110         return 0;
111 }
112
113 int
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)
116 {
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;
124         u32 outp, lane = 0;
125         u8  ver, hdr, cnt, len;
126         struct nvbios_dpout info;
127         int i;
128
129         /* -> 10Khz units */
130         link_bw *= 2700;
131
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),
136                         .bios = bios,
137                         .offset = 0x0000,
138                         .outp = dcbo,
139                         .crtc = head,
140                         .execute = 1,
141                 };
142
143                 while (link_bw < nv_ro16(bios, info.lnkcmp))
144                         info.lnkcmp += 4;
145                 init.offset = nv_ro16(bios, info.lnkcmp + 2);
146
147                 nvbios_exec(&init);
148         }
149
150         dpctrl |= ((1 << link_nr) - 1) << 16;
151         if (data & NV94_DISP_SOR_DP_LNKCTL_FRAME_ENH)
152                 dpctrl |= 0x00004000;
153         if (link_bw > 16200)
154                 clksor |= 0x00040000;
155
156         for (i = 0; i < link_nr; i++)
157                 lane |= 1 << (nv94_sor_dp_lane_map(priv, i) >> 3);
158
159         nv_mask(priv, 0x614300 + soff, 0x000c0000, clksor);
160         nv_mask(priv, 0x61c10c + loff, 0x001f4000, dpctrl);
161         nv_mask(priv, 0x61c130 + loff, 0x0000000f, lane);
162         return 0;
163 }
164
165 int
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)
168 {
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;
177
178         addr = nvbios_dpout_match(bios, type, mask, &ver, &hdr, &cnt, &len, &outp);
179         if (!addr)
180                 return -ENODEV;
181
182         addr = nvbios_dpcfg_match(bios, addr, 0, swing, preem, &ver, &hdr, &cnt, &len, &ocfg);
183         if (!addr)
184                 return -EINVAL;
185
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);
189         return 0;
190 }