18ef23b6fSBen Skeggs /*
28ef23b6fSBen Skeggs * Copyright 2021 Red Hat Inc.
38ef23b6fSBen Skeggs *
48ef23b6fSBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
58ef23b6fSBen Skeggs * copy of this software and associated documentation files (the "Software"),
68ef23b6fSBen Skeggs * to deal in the Software without restriction, including without limitation
78ef23b6fSBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
88ef23b6fSBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
98ef23b6fSBen Skeggs * Software is furnished to do so, subject to the following conditions:
108ef23b6fSBen Skeggs *
118ef23b6fSBen Skeggs * The above copyright notice and this permission notice shall be included in
128ef23b6fSBen Skeggs * all copies or substantial portions of the Software.
138ef23b6fSBen Skeggs *
148ef23b6fSBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
158ef23b6fSBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
168ef23b6fSBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
178ef23b6fSBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
188ef23b6fSBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
198ef23b6fSBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
208ef23b6fSBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
218ef23b6fSBen Skeggs */
2292fba5d3SBen Skeggs #include "priv.h"
23acbe9ecfSBen Skeggs #include "chan.h"
248ef23b6fSBen Skeggs #include "head.h"
258ef23b6fSBen Skeggs #include "ior.h"
26acbe9ecfSBen Skeggs
278c186c83SBen Skeggs #include <subdev/gsp.h>
28acbe9ecfSBen Skeggs #include <subdev/timer.h>
29168c0299SBen Skeggs
30168c0299SBen Skeggs #include <nvif/class.h>
318ef23b6fSBen Skeggs
32acbe9ecfSBen Skeggs static int
ga102_sor_dp_links(struct nvkm_ior * sor,struct nvkm_i2c_aux * aux)33acbe9ecfSBen Skeggs ga102_sor_dp_links(struct nvkm_ior *sor, struct nvkm_i2c_aux *aux)
34acbe9ecfSBen Skeggs {
35acbe9ecfSBen Skeggs struct nvkm_device *device = sor->disp->engine.subdev.device;
36acbe9ecfSBen Skeggs const u32 soff = nv50_ior_base(sor);
37acbe9ecfSBen Skeggs const u32 loff = nv50_sor_link(sor);
38acbe9ecfSBen Skeggs u32 dpctrl = 0x00000000;
39acbe9ecfSBen Skeggs u32 clksor = 0x00000000;
40acbe9ecfSBen Skeggs
41acbe9ecfSBen Skeggs switch (sor->dp.bw) {
42acbe9ecfSBen Skeggs case 0x06: clksor |= 0x00000000; break;
43acbe9ecfSBen Skeggs case 0x0a: clksor |= 0x00040000; break;
44acbe9ecfSBen Skeggs case 0x14: clksor |= 0x00080000; break;
45acbe9ecfSBen Skeggs case 0x1e: clksor |= 0x000c0000; break;
46acbe9ecfSBen Skeggs case 0x08: clksor |= 0x00100000; break;
47acbe9ecfSBen Skeggs case 0x09: clksor |= 0x00140000; break;
48acbe9ecfSBen Skeggs case 0x0c: clksor |= 0x00180000; break;
49acbe9ecfSBen Skeggs case 0x10: clksor |= 0x001c0000; break;
50acbe9ecfSBen Skeggs default:
51acbe9ecfSBen Skeggs WARN_ON(1);
52acbe9ecfSBen Skeggs return -EINVAL;
53acbe9ecfSBen Skeggs }
54acbe9ecfSBen Skeggs
55acbe9ecfSBen Skeggs dpctrl |= ((1 << sor->dp.nr) - 1) << 16;
56acbe9ecfSBen Skeggs if (sor->dp.mst)
57acbe9ecfSBen Skeggs dpctrl |= 0x40000000;
58acbe9ecfSBen Skeggs if (sor->dp.ef)
59acbe9ecfSBen Skeggs dpctrl |= 0x00004000;
60acbe9ecfSBen Skeggs
61acbe9ecfSBen Skeggs nvkm_mask(device, 0x612300 + soff, 0x007c0000, clksor);
62acbe9ecfSBen Skeggs
63acbe9ecfSBen Skeggs /*XXX*/
64acbe9ecfSBen Skeggs nvkm_msec(device, 40, NVKM_DELAY);
65acbe9ecfSBen Skeggs nvkm_mask(device, 0x612300 + soff, 0x00030000, 0x00010000);
66acbe9ecfSBen Skeggs nvkm_mask(device, 0x61c10c + loff, 0x00000003, 0x00000001);
67acbe9ecfSBen Skeggs
68acbe9ecfSBen Skeggs nvkm_mask(device, 0x61c10c + loff, 0x401f4000, dpctrl);
69acbe9ecfSBen Skeggs return 0;
70acbe9ecfSBen Skeggs }
71acbe9ecfSBen Skeggs
729a4514fbSBen Skeggs static const struct nvkm_ior_func_dp
739a4514fbSBen Skeggs ga102_sor_dp = {
749a4514fbSBen Skeggs .lanes = { 0, 1, 2, 3 },
759a4514fbSBen Skeggs .links = ga102_sor_dp_links,
769a4514fbSBen Skeggs .power = g94_sor_dp_power,
779a4514fbSBen Skeggs .pattern = gm107_sor_dp_pattern,
789a4514fbSBen Skeggs .drive = gm200_sor_dp_drive,
799a4514fbSBen Skeggs .vcpi = tu102_sor_dp_vcpi,
809a4514fbSBen Skeggs .audio = gv100_sor_dp_audio,
819a4514fbSBen Skeggs .audio_sym = gv100_sor_dp_audio_sym,
829a4514fbSBen Skeggs .watermark = gv100_sor_dp_watermark,
839a4514fbSBen Skeggs };
849a4514fbSBen Skeggs
85acbe9ecfSBen Skeggs static void
ga102_sor_clock(struct nvkm_ior * sor)86acbe9ecfSBen Skeggs ga102_sor_clock(struct nvkm_ior *sor)
87acbe9ecfSBen Skeggs {
88acbe9ecfSBen Skeggs struct nvkm_device *device = sor->disp->engine.subdev.device;
89acbe9ecfSBen Skeggs u32 div2 = 0;
90acbe9ecfSBen Skeggs
91acbe9ecfSBen Skeggs if (sor->asy.proto == TMDS) {
92acbe9ecfSBen Skeggs if (sor->tmds.high_speed)
93acbe9ecfSBen Skeggs div2 = 1;
94acbe9ecfSBen Skeggs }
95acbe9ecfSBen Skeggs
96acbe9ecfSBen Skeggs nvkm_wr32(device, 0x00ec08 + (sor->id * 0x10), 0x00000000);
97acbe9ecfSBen Skeggs nvkm_wr32(device, 0x00ec04 + (sor->id * 0x10), div2);
98acbe9ecfSBen Skeggs }
99acbe9ecfSBen Skeggs
100acbe9ecfSBen Skeggs static const struct nvkm_ior_func
10179c453afSBen Skeggs ga102_sor = {
102acbe9ecfSBen Skeggs .route = {
103acbe9ecfSBen Skeggs .get = gm200_sor_route_get,
104acbe9ecfSBen Skeggs .set = gm200_sor_route_set,
105acbe9ecfSBen Skeggs },
106acbe9ecfSBen Skeggs .state = gv100_sor_state,
107acbe9ecfSBen Skeggs .power = nv50_sor_power,
108acbe9ecfSBen Skeggs .clock = ga102_sor_clock,
1092274ce7eSBen Skeggs .bl = >215_sor_bl,
110f530bc60SBen Skeggs .hdmi = &gv100_sor_hdmi,
1119a4514fbSBen Skeggs .dp = &ga102_sor_dp,
1127bcf89eeSBen Skeggs .hda = &gv100_sor_hda,
113acbe9ecfSBen Skeggs };
114acbe9ecfSBen Skeggs
115acbe9ecfSBen Skeggs static int
ga102_sor_new(struct nvkm_disp * disp,int id)116acbe9ecfSBen Skeggs ga102_sor_new(struct nvkm_disp *disp, int id)
117acbe9ecfSBen Skeggs {
118acbe9ecfSBen Skeggs struct nvkm_device *device = disp->engine.subdev.device;
119acbe9ecfSBen Skeggs u32 hda = nvkm_rd32(device, 0x08a15c);
12079c453afSBen Skeggs
12179c453afSBen Skeggs return nvkm_ior_new_(&ga102_sor, disp, SOR, id, hda & BIT(id));
122acbe9ecfSBen Skeggs }
123acbe9ecfSBen Skeggs
1240407b33fSBen Skeggs static const struct nvkm_disp_func
1258ef23b6fSBen Skeggs ga102_disp = {
126acbe9ecfSBen Skeggs .oneinit = nv50_disp_oneinit,
12792fba5d3SBen Skeggs .init = tu102_disp_init,
12892fba5d3SBen Skeggs .fini = gv100_disp_fini,
12992fba5d3SBen Skeggs .intr = gv100_disp_intr,
1308ef23b6fSBen Skeggs .super = gv100_disp_super,
13192fba5d3SBen Skeggs .uevent = &gv100_disp_chan_uevent,
1328ef23b6fSBen Skeggs .wndw = { .cnt = gv100_disp_wndw_cnt },
1338ef23b6fSBen Skeggs .head = { .cnt = gv100_head_cnt, .new = gv100_head_new },
1348ef23b6fSBen Skeggs .sor = { .cnt = gv100_sor_cnt, .new = ga102_sor_new },
1358ef23b6fSBen Skeggs .ramht_size = 0x2000,
136168c0299SBen Skeggs .root = { 0, 0,GA102_DISP },
137168c0299SBen Skeggs .user = {
138168c0299SBen Skeggs {{-1,-1,GV100_DISP_CAPS }, gv100_disp_caps_new },
139889fcbe9SBen Skeggs {{ 0, 0,GA102_DISP_CURSOR }, nvkm_disp_chan_new, &gv100_disp_curs },
140889fcbe9SBen Skeggs {{ 0, 0,GA102_DISP_WINDOW_IMM_CHANNEL_DMA}, nvkm_disp_wndw_new, &gv100_disp_wimm },
141889fcbe9SBen Skeggs {{ 0, 0,GA102_DISP_CORE_CHANNEL_DMA }, nvkm_disp_core_new, &gv100_disp_core },
142889fcbe9SBen Skeggs {{ 0, 0,GA102_DISP_WINDOW_CHANNEL_DMA }, nvkm_disp_wndw_new, &gv100_disp_wndw },
143168c0299SBen Skeggs {}
144168c0299SBen Skeggs },
1458ef23b6fSBen Skeggs };
1468ef23b6fSBen Skeggs
1478ef23b6fSBen Skeggs int
ga102_disp_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_disp ** pdisp)148a7f000ecSBen Skeggs ga102_disp_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
149a7f000ecSBen Skeggs struct nvkm_disp **pdisp)
1508ef23b6fSBen Skeggs {
1518c186c83SBen Skeggs if (nvkm_gsp_rm(device->gsp))
152*9e994444SBen Skeggs return r535_disp_new(&ga102_disp, device, type, inst, pdisp);
1538c186c83SBen Skeggs
1541c6aab75SBen Skeggs return nvkm_disp_new_(&ga102_disp, device, type, inst, pdisp);
1558ef23b6fSBen Skeggs }
156